Given that x is an int, the following is valid:
switch(x){
case x 5 :System.out.println(“SMALL”);
default :System.out.println(“CORRECT”); break;
}
False:
- the type of the case labels must be consistent with the type of the switch condition.
Given: byte b = 1; char c = 1; short s = 1; int i = 1;
which of the following expressions are valid:
2, 3, 5
Given:
switch( m ){
case 32: System.out.println(“32”);break;
case 64: System.out.println(“64”);break;
case 128 : System.out.println(“128”);break; }
What is a valid type for m:
1, 3, 5
Consider: o1 and o2 denote two object references to two different objects of same class.
Which of the following statements are true:
1. o1.equals(o2) will always be false.
2. o1.hashCode() == o2.hashCode() will always be false.
3. o1 == o2 will always be false
4. Nothing can be said about o1.equals(o2) regarding what it will return based on the given information.
5. Nothing can be said about o1 == o2.
3, 4
- Note that both equals() and hashCode() methods can be overridden by the programmer so you can’t say anything about what they will return without looking at the code.
Which of the following will not give any error at compile time and run time:
1, 3, 4, 5
- All an if(…) needs is a boolean.
Which of the following statements are true:
1, 2, 5
True/false: A char value can always be assigned to an int variable
True.
- since the int type is wider than the char type.
Which operators will always evaluate all the operands:
2, 5
- If the condition before ? returns true, only the first operand will be evaluated, otherwise only the second operand is evaluated (4).