举一反三
- 分析程序,将代码补充完整class A { private int x; public A(int i) { x = i; } } class B extends A { private int y; public B(int i) { ___________ ____; y = i; } }
- 8.5 阅读程序,写出运行结果 class Point{ int x=1; static int y=2; public void show(){System.out.println(x+","+y); }} public class tempDemo{ public static void main(String []args){ Point p1=new Point();p1.show(); p1.x=2;p1.y=3; Point p2=new Point();p2.show(); p1.show(); p1.y=5; p2.show(); }}
- 下列代码中: class Point{ int x,y; public: Point(int a, int b=0); //① Point(Point &aPoint); //②Point(Point *p); //③ 默认的构造函数是 A: ① B: ② C: ③ D: 没有
- 有如下类定义: class AA{ int a; public: AA(int n=0):a(n){} }; class BB :public AA{ public: BB(int x) __________ };其中划线处应填写的内容是 A: :AA(x){} B: :a(n){} C: {a(x);} D: {a=x;}
- class Person {private int a;public int change(int m){ return m; }}public class Teacher extends Person {public int b;public static void main(String arg[]){Person p = new Person();Teacher t = new Teacher();int i;// point x}}在 // point x安排哪个语句合法?
内容
- 0
class Person {private int a;public int... // point x安排哪个语句合法?
- 1
下面代码中,没有定义内部类或者错误定义了内部类的是()。 A: public Class Line { int length; Class Point {//内部类代码}} B: public Class Line { public Point getPoint() { return new Point(){//内部类代码}; }} C: public Class Line { //外部类代码} Class Point {//内部类代码} D: public Class Line { public int calcLength() { Class Point {//内部类代码} }}
- 2
下列程序的输出结果是_________。 #include class point { public: point(int i,int j) {x=i;y=j;} void print() {cout<<'('< (5,7) (4,3) (9,10) (-5,-7) 10.61.5
- 3
如下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> } }
- 4
以下的类(接口)定义中正确的是( ) A: public class A{ private int x; public getX(){ return x; }} B: public abstract class A{ private int x; public abstract int getX(); public int aMethod(){ return 0; }} C: public class A{ private int x; public abstract int getX();} D: public interface interfaceA{ private int x; public int getX(){ return x; }}