单项选择题

public class X { 
public static void main (String[] args)  { 
byte b = 127; 
byte c = 126; 
byte d = b + c; 
} 
}  
Which statement is true?()  

A. Compilation succeeds and d takes the value 253.
B. Line 5 contains an error that prevents compilation.
C. Line 5 throws an exception indicating “Out of range”
D. Line 3 and 4 contain error that prevent compilation.
E. The compilation succeeds and d takes the value of 1.


您可能感兴趣的试卷

你可能感兴趣的试题

1.单项选择题Which is a valid identifier?()  

A. false
B. default
C. _object
D. a-class

2.单项选择题

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.

3.多项选择题

class BaseClass{ 
private float x= 1.0f; 
protected void setVar (float f) {x = f;} 
} 
class SubClass extends BaseClass   { 
private float x = 2.0f; 
//insert code here 
}  
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; }

5.单项选择题Which method is an appropriate way to determine the cosine of 42 degrees?()

A. Double d = Math.cos(42);
B. Double d = Math.cosine(42);
C. Double d = Math.cos(Math.toRadians(42));
D. Double d = Math.cos(Math.toDegrees(42));
E. Double d = Math.cosine(Math.toRadians(42));

8.单项选择题System.out.println(Math.sqrt(-4D));  What is the result?()  

A. –2
B. NaN
C. Infinity
D. Compilation fails.
E. An exception is thrown at runtime.

9.单项选择题Which interface does java.util.Hashtable implement?()  

A. java.util.Map
B. java.util.List
C. java.util.Hashable
D. java.util.Collection

10.单项选择题

public class Test { 
public static void main(String[] args) { 
String str = NULL; 
System.out.println(str); 
} 
}  
What is the result?()  

A. NULL
B. Compilation fails.
C. The code runs with no output.
D. An exception is thrown at runtime.