public class ClassA { public int getValue() { int value=0; boolean setting = true; String title=”Hello”; (value || (setting && title == “Hello”)) { return 1; } (value == 1 & title.equals(”Hello”)) { return 2; } } } And: ClassA a = new ClassA(); a.getValue(); What is the result?()
第1题:
有如下类定义: ClaSS MyClass{ int value; public: MyClass(int n):value(n){ } int getValue( )const{return value;} l; 则类MyClass的构造函数的个数是
A.1个
B.2个
C.3个
D.4个
第2题:
请阅读下面程序 public class ThreadTest{ public static void main(String args[]) ( Thread t1=new Thread(new Hello()); Thread t2=new Thread(new Hello()); t1.start(); t2.start(); } } class Hello implements Runnable { int i; public void run() { while(true) { System.out.prinfin("Hello"+i++); if(i=5) break; } } } 该程序创建线程使用的方法是
A.继承Thread类
B.实现Runnable接口
C.t1.start()
D.t2.start()
第3题:
( 28 ) 有如下程序
#include
using namespace std;
int i=1;
class Fun{
public:
static int i;
int value( ){ return i-1;}
int value( )const{ return i+1;}
};
int Fun::i=2;
int main( ){
int i=3;
Fun fun1;
const Fun fun2;
____________
return 0;
}
若程序的输出结果是 :
123
则程序中下划线处遗漏的语句是
A ) cout<<<Fun::i<
B ) cout<<Fun::i<<fun1.value()<
C ) cout<<<<Fun::i;
D ) cout<
第4题:
若有以下程序: #include<iostream> usingnamespacestd; classA { private: int x; public: int x; void setx(int i) { x=i; } int getx() { return x; } }; class B:public A { private: int m; public: int p; void setvalue (int a,int b,int C) { setx(A) ; z=b; m=c; } void display() { cout<<getx()<<","<<z<<","<<m<<end1; } }; int main() { B obj; obj.setvalue(2,3,4); obj.display(); return 0; } 程序运行以后的输出结果是
A.产生语法错误
B.2,3,4
C.2,2,2
D.4,3,2
第5题:
public class ClassA{public int getValue(){int value=0;boolean setting=true;String title="Hello";if(value||(setting && title=="Hello")){return 1;}if(value==1&title.equals("Hello")){return 2;}}}And:ClassA a=new ClassA();a.getValue();What is the result?()
A.1
B.2
C.Compilation fails.
D.The code runs with no output.
E.An exception is thrown at runtime.
第6题:
通过实现Rmmable接口创建线程,请在下面横线处填写代码完成此程序。
public class ThreadTest
{
public static void main(String args [])
{
Thread testObj1 = new Thread (new Hello ());
Thread testObj2 = new Thread (new Hello ());
testObj 2.start ( );
}
}
class Hello implements Runnable
{
int j;
public void run()
{
System.out.println("Hello" + j ++);
}
}
第7题:
有如下程序 #include <iostream>using namespace std;int i=1;class Fun {public:static int i;int value(){ return i-1;}int value()const{ return i+1;}};int Fun:: i=2;int main() {int i=3;Fun fun1;const Fun fun2;______________________return ();}若程序的输出结果是:123
A.cout<<fun1.value()<<Fun:: i<<fun2.value();
B.cout<<Fun::i<<fun1.value()<<fun2.value();
C.cout<<fun1. value()<<fun2.value()<<Fun:: i;
D.cout<<fun2.value()<<Fun:: i<<fun 1.value();
第8题:
有如下程序 #include <iostream> using namespace std; int i=1; class Fun { public: static int i; int value( ){ return i-l;} int value( )const { return i+1;} }; int Fun::i=2; int main( ){ int i=3; Fun funl; const Fun fun2; ___________ return 0; } 若程序的输出结果是: 123 则程序中下划线处遗漏的语句是
A.cout<<funl.value( )<<Fun::i<<fun2.value( );
B.cout<<Fun::i<<funl.value()<<fun2.value( );
C.cout<<funl.value( )<<fun2.value( )<<Fun::i;
D.cout<<fun2.value( )<<Fun::i<<fun1.value( );
第9题:
publicclassClassA{publicintgetValue(){intvalue=0;booleansetting=true;Stringtitle=”Hello”;(value||(setting&&title==Hello”)){return1;}(value==1&title.equals(”Hello”)){return2;}}}And:ClassAa=newClassA();a.getValue();Whatistheresult?()
A.1
B.2
C.Compilationfails.
D.Thecoderunswithnooutput.
E.Anexceptionisthrownatruntime.
第10题:
有如下程序: #include<iostream> using namespace std; classA { public: A(){cout<<"A";} }; class B{public:B(){cout<<"B";}}; class C:public A { B b; public: C(){cout<<"C";} }; int main(){C obj;return 0;} 执行后的输出结果是( )
A.ABC
B.BAC
C.ACB
D.CBA