class super {  p

题目

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

第1题:

下面程序输出的结果为

#include"iostream.h"

class A

{

public:

A( ){cout<<"CLASS A"<<endl;}

~A( ){}

};

class B:public A

{

public:

B( ){cout<<"CLASS B"<<endl;}

~B( ){}

};

void main( )

{

A*p;

p=new B;

B *q;

q=new B;

}

A.CLASS A CLASS B

B.CLASS A CLASS B CLASS B

C.CLASS A CLASS B CLASS A CLASS B

D.CLASS A CLASS B CLASS B CLASS B


正确答案:C
解析:每实例化一个类就要调用其构造函数,结束运行该实例后调用析构函数。注意:类的实例化和构造函数、析构函数的调用方式和何时调用。

第2题:

下面程序输出的结果为 #include"iostream.h” class A { public: A(){cout<<"CLASSA"<<endl;} ~A() {} }; class B:public A { public: B(){cout<<"CLASS B"<<endl;} ~B(){} }; void main() { A*p; p=new B;

A.CLASS A CLASS B CLASS B CLASS B

B.CLASS A CLASS B CLASS A CLASS B

C.CLASS A CLASS B CLASS B

D.CLASS A CLASS B


正确答案:C

第3题:

Click the Exhibit button. What two must the programmer do to correct the compilation errors? ()

A.insert a call to this() in the Car constructor

B.insert a call to this() in the MeGo constructor

C.insert a call to super() in the MeGo constructor

D.insert a call to super(vin) in the MeGo constructor

E.change the wheelCount variable in Car to protected

F.change line 3 in the MeGo class to super.wheelCount = 3;


参考答案:D, E

第4题:

The lower-level classes(known as subclasses or derived classes) ( )state andbehavior from the higher-level class(known as a super class or base class).

A.request
B.inherit
C.invoke
D.accept

答案:B
解析:
低层的类(也称子类或派生类)从高层类(也称为超类或基类)中继承了状态和行为。

第5题:

下列程序的输出结果是

class Father{

int m.n;

Father(int a,int B)

{ m=a;

n=b

}

void show ( ){

System.out.println("m and n:"+m+" "+n);

}

}

class Son extends Father{

int p;

Son (int a,int b,int C)

{ super(a,B) ;

p=c;

}

void show(){supur.show( );

System.out.println("p:"+p);

}

}

class Test {

public static void main (String args[ ])

{ Son s:new Son(6,7,8);

s.show( );

}

}

A.m and n:6 8 p:7

B.m andn:6 7 p:8

C.m and n:7 8 p:6

D.m and n:8 7 p:6


正确答案:B
解析:如果你希望访问一个覆盖方法的超类版本,可以通过super来做到这一点,本题中show()的超类版本在子类版本内被调用。

第6题:

已知: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。

第7题:

下面程序输出的结果为( )。 #inClUde”iostream.h” Class A {public: A(){cout<<“CLASS A”<<endl;} ~A()<)}; class B:public A {public: B(){cout<<”CLASSB”<<endl;} ~B(){}}; void main() {A*p; p=new B; B *q; q=new B;}

A.CLASS A CLASS B

B.CLASS A CLASS B CLASS B

C.CLASS A ClASS B

D.CLASS A CLASS B CLASS A CLASS B CLASS B CLASS B


正确答案:C
解析: 本题考查类的继承、类的实例化和构造函数、析构函数的调用方式和何时调用。每实例化一个类就要调用其构造函数,结束运行该实例后调用析构函数。

第8题:

下面程序输出的结果为 #include"iostream.h" class A { public: A(){cout<<"CLASSA"<<endl;} ~A() {} }; class B:public A { public: B(){cout<<"CLASSB"<<endl;} ~B() {} }; void main() { A * p; p=new B; B *q; q=new B; }

A.CLASS A CLASS B

B.CLASS A CLASS B CLASS B

C.CLASS A CLASS B CLASS A CLASS B

D.CLASS A CLASS B CLASS B CLASS B


正确答案:C
解析:每实例化一个类就要调用其构造函数,结束运行该实例后调用析构函数。注意:类的实例化和构造函数、析函数的调用方式和何时调用。

第9题:

The lower-level classes (known as subclasses or derived classes) ( ) state and behavior from the higher-level class (known as a super class or base class).

A.request B.inherit C.invoke D.accept


正确答案:B

第10题:

public class Person {  private String name, comment;  private int age;  public Person(String n, int a, String c) {  name = n; age = a; comment = c;  }  public boolean equals(Object o) {  if(! (o instanceof Person)) return false;  Person p = (Person)o;  return age == p.age && name.equals(p.name);  }  }  What is the appropriate definition of the hashCode method in class Person?() 

  • A、 return super.hashCode();
  • B、 return name.hashCode() + age * 7;
  • C、 return name.hashCode() + comment.hashCode() /2;
  • D、 return name.hashCode() + comment.hashCode() / 2 - age * 3;

正确答案:B

更多相关问题