Which keyword is used to prevent a class from being subclassed in Java?
Aabstract
Bfinal
Cstatic
Dsealed
Correct Answer:
B. final
EXPLANATION
The 'final' keyword prevents a class from being extended. 'sealed' (Java 17+) allows selective subclassing, but 'final' is the standard way to prevent all subclassing.
Which keyword is used to achieve runtime polymorphism in Java?
Afinal
Bstatic
Cvirtual
DNone of the above
Correct Answer:
D. None of the above
EXPLANATION
Java achieves runtime polymorphism through method overriding using inheritance. Unlike C++, Java doesn't use the 'virtual' keyword; it's implicit for all non-final methods.
Which of the following correctly describes encapsulation?
AWrapping data and methods together and hiding internal details
BCreating multiple classes with same functionality
CExtending one class from another
DImplementing an interface
Correct Answer:
A. Wrapping data and methods together and hiding internal details
EXPLANATION
Encapsulation is the bundling of data (variables) and methods into a single unit (class) while hiding the internal implementation details from the outside world. It is achieved using access modifiers.