Compilation fails.
“odd” will always be output.
“even” will always be output.
“odd” will be output for odd values of x, and “even” for even values.
“even” will be output for add values of x, and “odd” for even values.
第1题:
A.public class test { public int x = 0; public test(int x) { this.x = x; } }
B.public class Test{ public int x=0; public Test(int x) { this.x = x; } }
C.public class Test extends T1, T2 { public int x = 0; public Test (int x) { this.x = x; } }
D.public class
第2题:
若有以下程序: #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
第3题:
运行下面的程序时,会产生( )。 public class Test{ public static void main(String args[ ] ) { int x =0; int y = 2/x; int z[ ] = {1,2,4,6}; int p=z[4]; } }
A.ArrayIndexOutOfBoundsExcePtion异常
B.NumberFormatException异常
C.ArithmeticException异常
D.ArithmeticException异常和ArrayIndexOutOfBoundsExcePtion异常
第4题:
在下列源代码文件Test.java中,正确定义类的代码是( )。
A.pblic class test { public int x=0; public test(int x) { this. x=x;} }
B.public class Test { public int x=0; public Test(int x) { this. x=x;} }
C.public class Test extends T1,T2{ public int x = 0; public Test(int x){ this. x = x; } }
D.protected class Test extends T2{ public int x = 0; public Test(int x) { this. x = x; } }
第5题:
以下程序的执行结果是______。
include<iostream.h>
class A
{
int a:
public:
void seta(int x) {a=x;}
void showa() {cout<<a<<end1;}
};
class B
{
int b;
public:
void setb(int x) {b=x;}
void showb(){cout<<b<<end1;}
};
第6题:
下列程序的运行结果是【 】。
include <iostream. h>
class test
{
private:
int num;
public:
test()
int TEST() {return num+100;}
~test()
};
test::test(){num=0;}
test::~test(){cout<<"Destructor is active"<<endl;}
void main()
{
test x[3]
cout<<x[1]. TEST()<<endl;
}
第7题:
完成下列类的构造函数,初始化语句为______。
include<iostream.h>
class Test
{
private:
int x,y;
public:
void Test(int initx,int inity){
______
}
void printx( ){cout<<x<<"-"<<y<<"="<<x-y;}
};
void main( )
{
Test x(300,200);
x.printx( );
}
第8题:
执行下面程序段,屏幕上将输出( )。 public class Test { private int x=10,y=20; public Test (int x,int y) { System.out.println (x+this.x); System.out.println (y+y); } public static void main (String[] args) { Testt= new Test(30,50); } }
A.无输出
B.20 40
C.40 100
D.40 70
第9题:
执行下列代码段之后,变量z的值为______。 Public class Test8 { public static void main(String[] args) { int x=2; int y=3; int z=4; z-....= y-x--; System.out.println(z); }
A.1
B.2
C.3
D.4
第10题:
有如下类定义: class Test { private int x; public int y; public void setX (int m) {x=m;} public int getX( ) {return x;} }现用Test t=new Text();生成一个对象t,则如下语句中,错误的是( )。
A.t.x=10;
B.t.y=10;
C.t. setX(10);
D.int m=t.getX( );