Which statement is true about the switch statement?
It must contain the default section.
The break statement, at the end of each case block, is optional.
Its case label literals can be changed at runtime.
Its expression must evaluate to a collection of values.
Correct answer: B
Question 2
Given the code fragment:
What is the result?
Sum is 600
Compilation fails at line n1.
Compilation fails at line n2.
A ClassCastException is thrown at line n1.
A ClassCastException is thrown at line n2.
Correct answer: C
Question 3
What is the name of the Java concept that uses access modifiers to protect variables and hide them within a class?
Encapsulation
Inheritance
Abstraction
Instantiation
Polymorphism
Correct answer: A
Explanation:
Using the private modifier is the main way that an object encapsulates itself and hide data from the outside world. Reference: http://www.tutorialspoint.com/java/java_access_modifiers.htm
Using the private modifier is the main way that an object encapsulates itself and hide data from the outside world.