Java Programming — OOP in Java
Java OOP, collections, multithreading
27 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 27 questions in OOP in Java
Q.1 Easy OOP in Java
Which keyword is used to prevent a class from being subclassed in Java?
A abstract
B final
C static
D sealed
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.

Take Test
Q.2 Easy OOP in Java
What is the default access modifier for a class member in Java if no modifier is specified?
A public
B private
C protected
D package-private (default)
Correct Answer:  D. package-private (default)
EXPLANATION

When no access modifier is specified, the member has package-private (default) access, visible only within the same package.

Take Test
Q.3 Easy OOP in Java
Can you instantiate an interface in Java?
A Yes, directly with new keyword
B No, interfaces cannot be instantiated
C Yes, only if it has default methods
D Yes, if it has only abstract methods
Correct Answer:  B. No, interfaces cannot be instantiated
EXPLANATION

Interfaces cannot be instantiated directly. You can only create objects of classes that implement interfaces.

Take Test
Q.4 Easy OOP in Java
Which keyword is used to prevent a class from being subclassed?
A abstract
B final
C sealed
D static
Correct Answer:  B. final
EXPLANATION

The 'final' keyword prevents a class from being extended. For example: final class MyClass {} cannot be subclassed.

Take Test
Q.5 Easy OOP in Java
What is the default access modifier for class members in Java if not explicitly specified?
A public
B private
C protected
D package-private (default)
Correct Answer:  D. package-private (default)
EXPLANATION

If no access modifier is specified for a class member, it has package-private (default) access, meaning it's accessible only within the same package.

Take Test
Advertisement
Q.6 Easy OOP in Java
What is the access modifier of members declared in an interface?
A private
B protected
C public
D package-private
Correct Answer:  C. public
EXPLANATION

All members in an interface are implicitly public. Variables are public static final, and methods are public abstract (unless default or static).

Take Test
Q.7 Easy OOP in Java
Can a class extend multiple classes in Java?
A Yes, using multiple inheritance
B No, Java supports only single inheritance
C Yes, but only if they are abstract classes
D Yes, using the 'extends' keyword multiple times
Correct Answer:  B. No, Java supports only single inheritance
EXPLANATION

Java supports only single class inheritance to avoid the diamond problem. However, multiple interface implementation is allowed.

Take Test
Q.8 Easy OOP in Java
Which keyword is used to achieve runtime polymorphism in Java?
A final
B static
C virtual
D None 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.

Take Test
Q.9 Easy OOP in Java
What happens when you try to instantiate an interface in Java?
A It creates an anonymous inner class instance
B It throws a compile-time error
C It throws a runtime error
D It works like a normal class instantiation
Correct Answer:  B. It throws a compile-time error
EXPLANATION

Interfaces cannot be instantiated directly. You must create a concrete class that implements the interface or use an anonymous inner class.

Take Test
Q.10 Easy OOP in Java
Which of the following correctly describes encapsulation?
A Wrapping data and methods together and hiding internal details
B Creating multiple classes with same functionality
C Extending one class from another
D Implementing 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.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips