单项选择题

class super {  
public int getLength() {return 4;}  
 }  
public class Sub extends Super {  
public long getLength() {return 5;}  
public static void main (Stringargs) {  
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.多项选择题Which two statements are true regarding the creation of a default constructor? ()  

A. The default constructor initializes method variables.
B. The compiler always creates a default constructor for every class.
C. The default constructor invokes the no-parameter constructor of the superclass.
D. The default constructor initializes the instance variables declared in the class.
E. When a class has only constructors with parameters, the compiler does not create a default  constructor.

2.单项选择题

 public class ArrayTest {  
public static void main (Stringargs) { 
 float f1, f2;  
f1 = new float [10]; 
f2 = f1;  
System.out.printIn (“f2[0]=” + f2[0]);  
} 
}  
What is the result?()

A. It prints f2[0] = 0.0
B. It prints f2[0] = NaN
C. An error at line 5 causes compile to fail.
D. An error at line 6 causes compile to fail.
E. An error at line 6 causes an exception at runtime.

5.单项选择题

public class Mycircle {  
public double radius;  
public double diameter;  
public void setRadius(double radius)  
this.radius = radius;  
this.diameter= radius * 2;  
}  
public double getRadius() { 
return radius;  
}  
Which statement is true?()  

A. The Mycircle class is fully encapsulated.
B. The diameter of a given MyCircle is guaranteed to be twice its radius.
C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation.
D. The radius of a MyCircle object can be set without affecting its diameter.

6.多项选择题Which two statements are true?()

A. An inner class may be declared as static.
B. An anonymous inner class can be declared as public.
C. An anonymous inner class can be declared as private.
D. An anonymous inner class can extend an abstract class.
E. An anonymous inner class can be declared as protected.

8.单项选择题

class A {  
public byte getNumber () {  
return 1;  
}  
}  
class B extends A {  
public short getNumber() {  
return 2;  
}  
 public static void main (String args) {  
B b = new B ();  
 System.out.printIn(b.getNumber()) 
}  
}  
What is the result?()  

A. Compilation succeeds and 1 is printed.
B. Compilation succeeds and 2 is printed.
C. An error at line 8 causes compilation to fail.
D. An error at line 14 causes compilation to fail.
E. Compilation succeeds but an exception is thrown at line 14.

9.单项选择题Which statement about static inner classes is true?()

A. An anonymous class can be declared as static.
B. A static inner class cannot be a static member of the outer class.
C. A static inner class does not require an instance of the enclosing class.
D. Instance members of a static inner class can be referenced using the class name of the static inner class.

10.多项选择题

class BaseClass{  
private float x= 1.0f;  
protected void setVar (float f) {x = f;}  
}  
class SubClass exyends BaseClass {  
private float x = 2.0f;  
//insert code here  8. }  
Which two are valid examples of method overriding?()

A. Void setVar(float f) {x = f;}
B. Public void setVar(int f) {x = f;}
C. Public void setVar(float f) {x = f;}
D. Public double setVar(float f) {x = f;}
E. Public final void setVar(float f) {x = f;}
F. Protected float setVar() {x=3.0f; return 3.0f; }

最新试题

Which code, inserted at line 4, guarantees that this program will output [1, 2]?()

题型:单项选择题

What is the output if the main()  method is run?()

题型:单项选择题

A programmer must create a generic class MinMax and the type parameter of MinMax must implement Comparable. Which implementation of MinMax will compile?()

题型:单项选择题

Given:  foo and bar are public references available to many other threads, foo refers to a Thread and bar is an Object. The thread foo is currently executing bar.wait().  From another thread, what provides the most reliable way to ensure that foo will stop executing wait()?()

题型:单项选择题

What is the result?()

题型:单项选择题

Which statement is true?()

题型:单项选择题

What is the result?()

题型:单项选择题

Given a class whose instances, when found in a collection of objects, are sorted by using the compareTo() method, which two statements are true?()

题型:多项选择题

Which two are possible results?()

题型:多项选择题

Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5?()

题型:多项选择题