单选题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() 

题目
单选题
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
解析: 暂无解析
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

设有类定义如下:

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

第2题:

class A {   public String toString () {   return “4”;   }   }   class B extends A {   8. public String toString () {   return super.toString() + “3”;   }   }   public class Test {   public static void main(Stringargs) {   System.out.printIn(new B());   }   }   What is the result?()  

  • A、 Compilation succeeds and 4 is printed.
  • B、 Compilation succeeds and 43 is printed.
  • C、 An error on line 9 causes compilation to fail.
  • D、 An error on line 14 causes compilation to fail.
  • E、 Compilation succeeds but an exception is thrown at line 9.

正确答案:B

第3题:

执行下列代码后,输出的结果为( )。 class Base { int x = 30; void setX( ) {x=1O;} } class SubClass extends Base { int x=40; void setX ( ) {x=20;} int getX( ) {return super. x; } } public class Test { public static void main(String[ ] args) { SubClass sub=new SubClass( ); sub. setX( ); System. out. println(sub, getX( ) ); } }

A.10

B.20

C.30

D.40


正确答案:C
解析:本题主要考查有关类的继承方面的知识。Java中,类是分层次的,当子类的成员变量与父类的成员变量名字相同时,子类的成员变量会隐藏父类的成员变量,当子类的成员方法与父类的成员方法名字、参数列表、返回值类型都相同时,子类的方法是父类的方法的重写。这样,在子类的对象调用方法时,是按照子类中方法定义执行,隐藏父类的方法的定义。当子类隐藏了父类的变量,并重写了父类的方法后,又要使用父类变量或父类被重写的方法时,可通过super来实现对父类变量的访问和父类方法的调用。因此,本题中在main ()中调用setX ()时,是调用的SubClass类中的setX ()函数,同时将SubClass类中的i变量值设为20。当main ()函数中调用getX ()函数时,并不是取了SubClass类中的i的值,而是取的Base类中i变量的值,此时i的值为其初始值30。

第4题:

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

  • A、 4, 4
  • B、 4, 5
  • C、 5, 4
  • D、 5, 5
  • E、 The code will not compile.

正确答案: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、 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

第6题:

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

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

正确答案:A

第7题:

1. class Super {  2. public float getNum() { return 3.0f; }  3. }  4.   5. public class Sub extends Super {  6.   7. }  Which method, placed at line6, causes compilation to fail?()  

  • A、 public void getNum(){}
  • B、 public void getNum(double d){}
  • C、 public float getNum() { return 4.0f; }
  • D、 public double getNum(float d) { return 4.0d; }

正确答案:A

第8题:

以下程序调试结果为:

public class Test {

int m=5;

public void some(int x) {

m=x;

}

public static void main(String args []) {

new Demo().some(7);

}

}

class Demo extends Test {

int m=8;

public void some(int x) {

super.some(x);

System.out.println(m);

}

}

A.5

B.8

C.7

D.无任何输出

E.编译错误


正确答案:B

第9题:

class super {   public float getNum() {return 3.0f;}   }   public class Sub extends Super {   }   Which method, placed at line 6, will cause a compiler error?()

  • A、 Public float getNum() {return 4.0f; }
  • B、 Public void getNum (){}
  • C、 Public void getNum (double d){}
  • D、 Public double getNum (float d) {retrun 4.0f; }

正确答案:B

第10题:

class A {  public A() {  System.out.println(“hello from a”);  }  }  class B extends A {  public B () {  System.out.println(“hello from b”);  super();  }  }  public class Test {  public static void main(String args[]) {  A a = new B();  }  }   What is the result when main is executed?()  

  • A、 Compilation fails.
  • B、 hello from a
  • C、 hello from b
  • D、 hello from b hello from a
  • E、 hello from a hello from b

正确答案:A

更多相关问题