Home
31.
Which of the following properties of an enum can be marked abstract ?
  • A.
    The enum class definition
  • B.
    An enum method
  • C.
    An enum value
  • D.
    None of the above
  • Answer & Explanation
  • Report
Answer : [B]
Explanation :
An enum cannot be marked abstract , nor can any of its values, but its methods can be marked abstract , making Option B the correct answer. Note that if an enum contains an abstract method, then every enum value must include an override of this abstract method.
Report
Name Email  
32.
What is the output of the following application?
package world; public class Matrix { private int level = 1; class Deep { private int level = 2; class Deeper { private int level = 5; public void printReality() { System.out.print(level); System.out.print(" "+Matrix.Deep.this.level); System.out.print(" "+Deep.this.level); } } } public static void main(String[] bots) { Matrix.Deep.Deeper simulation = new Matrix().new Deep().new Deeper(); simulation.printReality(); } }
  • A.
    1 1 2
  • B.
    5 2 2
  • C.
    5 2 1
  • D.
    The code does not compile.
  • Answer & Explanation
  • Report
Answer : [B]
Explanation :
The code compiles without issue, so Option D is incorrect. The first print()statement refers to value in the Deeper class, so 5 is printed. The second and third print() statements actually refer to the same value in the Deep class, so 2 is printed twice. The prefix Matrix. is unnecessary in the first of the two print() statements and does not change the result. For these reasons, Option B is the correct answer.
Report
Name Email  
33.
A local inner class can access which type of local variables?
I. final
II. private
III. effectively final
  • A.
    I only
  • B.
    I and II
  • C.
    III only
  • D.
    I and III
  • Answer & Explanation
  • Report
Answer : [D]
Explanation :
A local inner class can access final or effectively final local variables, making Option D the correct answer. The second statement is invalid because access modifiers like private cannot be applied to local variables.
Report
Name Email  
34.
What is the output of the following application?
package finance;
enum Currency {
DOLLAR, YEN, EURO
}
abstract class Provider {
protected Currency c = Currency.EURO;
}
public class Bank extends Provider {
protected Currency c = Currency.DOLLAR;
public static void main(String[] pennies) {
int value = 0;
switch(new Bank().c) {
case 0:
value--; break;
case 1:
value++; break;
}
System.out.print(value);
}
}
  • A.
    0
  • B.
    1
  • C.
    The code does not compile.
  • D.
    The code compiles but throws an exception at runtime.
  • Answer & Explanation
  • Report
Answer : [C]
Explanation :
The type of the variable in the switch statement is the enum Currency , but the case statements use int values. While the enum class hierarchy does support an ordinal() method, which returns an int value, the enum values cannot be compared directly with int values. For this reason, the code does not compile, since the case statement values are not compatible with the variable type in the switch statement, making Option C the correct answer.
Report
Name Email  
35.
What statement best describes the notion of effectively final in Java?
  • A.
    A local variable that is marked final
  • B.
    A static variable that is marked final
  • C.
    A local variable that is not marked final but whose primitive value or object reference does not change after it is initialized
  • D.
    A local variable that is not marked final but whose primitive value or object reference does not change after a certain point in the method
  • Answer & Explanation
  • Report
Answer : [C]
Explanation :
A local variable is effectively final when it’s primitive value or object reference does not change after it is initialized, making Option C the correct answer. Option D is incorrect. Any change to the variable after it is initialized disqualifies it for being considered effectively final.
Report
Name Email