定义类A和类B如下,得到结果是
class A{
int x;
A(int i){x=i;}
}
class B extends A{
double b=5.5;
}
class A{
int x;
A(int i){x=i;}
}
class B extends A{
double b=5.5;
}
举一反三
- 定义类A和类B如下,得到结果是class A{int x;A(int i)...s A{double b=5.5;}
- 若有如下类A的定义,下列哪些类正确继承了该类: abstract class A { abstract void method1(int i); abstract void method2(int j); } A: abstract class B extends A{ void method1( ) { } void method2( ) { } } B: class B { void method1(int i ) { } void method2(int j ) { } } C: class B implements A { void method1(int i ) { } void method2(int j ) { } } D: class B extends A{ public void method1(int x ) { } public void method2(int y ) { } }
- 分析程序,将代码补充完整class A { private int x; public A(int i) { x = i; } } class B extends A { private int y; public B(int i) { ___________ ____; y = i; } }
- 如下A类的定义中,不可以使用new A( )创建对象的是 A: public class A { int x; double d; } B: public class A { int x; double d; public A(){ <br> } } C: public class A { int x; double d; public A(){ x = 1; d = 0.5; } } D: public class A { int x; double d; public A(int x,double d){ this.x = x;<br> this.d = d; } } E: public class A { int x; double d; public A(int x,double d){ this.x = x;<br> this.d = d; } public A( ){ <br> } }
- 有如下类定义:public class S extends F{S(int x){ }S(int x,int y) {super(x,y);}}则类F中一定有构造方法