1. class Super {  2. private int a;  3. protected Super(int a) { this.a = a; }  4. }  .....  11. class Sub extends Super {  12. public Sub(int a) { super(a); }  13. public Sub() { this.a= 5; }  14. }  Which two, independently, will allow Sub to compile?()

题目

1. class Super {  2. private int a;  3. protected Super(int a) { this.a = a; }  4. }  .....  11. class Sub extends Super {  12. public Sub(int a) { super(a); }  13. public Sub() { this.a= 5; }  14. }  Which two, independently, will allow Sub to compile?()

  • A、 Change line 2 to: public int a;
  • B、 Change line 2 to: protected int a;
  • C、 Change line 13 to: public Sub() { this(5); }
  • D、 Change line 13 to: public Sub() { super(5); }
  • E、 Change line 13 to: public Sub() { super(a); }
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

1. public class SimpleCalc {  2. public int value;  3. public void calculate() { value += 7; }  4. } And:  1. public class MultiCalc extends SimpleCalc {  2. public void calculate() { value -= 3; }  3. public void calculate(int multiplier) {  4. calculate();  5. super.calculate();  6. value *=multiplier;  7. }  8. public static void main(String[] args) {  9. MultiCalc calculator = new MultiCalc();  10. calculator.calculate(2);  11. System.out.println(”Value is: “+ calculator.value);  12. }  13. }  What is the result?() 

  • A、 Value is: 8
  • B、 Compilation fails.
  • C、 Value is: 12
  • D、 Value is: -12
  • E、 The code runs with no output.
  • F、 An exception is thrown at runtime.

正确答案:A

第2题:

Which statements concerning the following code are true?()   class a {   public a() {}   public a(int i) { this(); }   }   class b extends a {   public boolean b(String msg) { return false; }   }   class c extends b  {  private c() { super(); }   public c(String msg) { this(); }   public c(int i) {}   }  

  • A、The code will fail to compile.
  • B、The constructor in a that takes an int as an argument will never be called as a result of constructing an     object of class b or c.
  • C、Class c has three constructors.
  • D、Objects of class b cannot be constructed.
  • E、At most one of the constructors of each class is called as a result of constructing an object of class c.

正确答案:B,C

第3题:

已知:Manager extends Employee观察:public Manager(String n,double s,int year,int month,int day) { super(n,s,year,month,day); bonus=0; }其中super是 ( )

A.Object类

B.Manager类

C.Employee类

D.Class类


正确答案:C
解析:本题中有extends这说明是继承,子类Manager继承父类Employee,使用变量super能够实现对父类成员的访问,所以本题中super指的是父类Employee。

第4题:

Assume that country is set for each class.  Given:  10. public class Money {  11. private String country, name;  12. public getCountry() { return country; }  13.}  and:  24. class Yen extends Money {  25. public String getCountry() { return super.country; }  26. }  27.  28. class Euro extends Money {  29. public String getCountry(String timeZone) {  30. return super.getCountry();  31. }  32. }  Which two are correct?()

  • A、 Yen returns correct values.
  • B、 Euro returns correct values.
  • C、 An exception is thrown at runtime.
  • D、 Yen and Euro both return correct values.
  • E、 Compilation fails because of an error at line 25.
  • F、 Compilation fails because of an error at line 30.

正确答案:B,E

第5题:

class Super { public int getLenght() { return 4; } } public class Sub extends Super { public long getLenght() { return 5; } public static void main(String[] args) {Super sooper = new Super(); Sub sub = new Sub(); System.out.println( sooper.getLenght() + “,” + sub.getLenght() ); } } What is the output? ()

  • A、 4,4
  • B、 4,5
  • C、 5,4
  • D、 5,5
  • E、 Compilation fails.

正确答案:E

第6题:

class Super {  public int getLenght( ) { return 4; }  }  public class Sub extends Super {  public long getLenght( ) { return 5; }  public static void main(String[] args) {  Super sooper = new Super( );  Sub sub = new Sub( );  System.out.println(  sooper.getLenght( ) + “,” + sub.getLenght( ) );  }  } What is the output?()

  • A、 Just after line 13.
  • B、 Just after line 14.
  • C、 Just after line 15.
  • D、 Just after line 16 (that is, as the method returns).

正确答案:C

第7题:

class Super {  public int i = 0;  public Super(String text) {  i = 1; }  }  public class Sub extends Super {  public Sub(String text) {  i = 2;  }   public static void main(String args[]) {  Sub sub = new Sub(“Hello”);  System.out.println(sub.i);  }  }  What is the result?()  

  • A、 0
  • B、 1
  • C、 2
  • D、 Compilation fails.

正确答案:C

第8题:

设有类定义如下:

class Base{

public Base(int i){}

}

public class MyOver extends Base{

public static void main(String arg[]){

MyOver m = new MyOver(10);

}

MyOver(int i){

super(i);

}

MyOver(String s, int i){

this(i);

//Here

}

}

以下哪条语句可以安排在//Here处 ?

A.MyOver m = new MyOver();

B.super();

C.this("Hello",10);

D.Base b = new Base(10);


正确答案:D

第9题:

10. interface Foo { int bar(); }  11. public class Sprite {  12. public int fubar( Foo foo) { return foo.bar(); }  13. public void testFoo() {  14. fubar(  15. // insert code here  16.);  17. }  18. }  Which code, inserted at line 15, allows the class Sprite to compile?() 

  • A、 Foo { public int bar() { return 1; } }
  • B、 new Foo { public int bar() { return 1; } }
  • C、 newFoo() { public int bar(){return 1; } }
  • D、 new class Foo { public int bar() { return 1; } }

正确答案:C

第10题:

class ClassA {  public int numberOfinstances;  protected ClassA(int numberOfinstances) {  this.numberOflnstances = numberOfinstances;  }  }  public class ExtendedA extends ClassA {  private ExtendedA(int numberOfinstances) {  super(numberOflnstances);  }  public static void main(String[] args) {  ExtendedA ext = new ExtendedA(420);  System.out.print(ext.numberOflnstances);  }  }  Which is true?() 

  • A、 420 is the output.
  • B、 An exception is thrown at runtime.
  • C、 All constructors must be declared public.
  • D、 Constructors CANNOT use the private modifier.
  • E、 Constructors CANNOT use the protected modifier.

正确答案:A

更多相关问题