Java Programming — OOP in Java
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 61–70 of 100 questions in OOP in Java
Q.61 Easy OOP in Java
What is the primary purpose of the 'super' keyword in Java?
A To create an instance of the parent class
B To access parent class methods and constructors
C To declare a variable as final
D To implement multiple inheritance
Correct Answer:  B. To access parent class methods and constructors
EXPLANATION

The 'super' keyword is used to refer to parent class methods, constructors, and variables. It allows a child class to access parent class members.

Take Test
Q.62 Medium OOP in Java
Which of the following is NOT a characteristic of an interface in Java?
A Can have abstract methods
B Can have static final variables
C Can have private instance variables (Java 9+)
D Can extend multiple interfaces
Correct Answer:  C. Can have private instance variables (Java 9+)
EXPLANATION

Interfaces cannot have instance variables (private or otherwise). They can only have constants (static final). Java 9+ allows private methods but not private instance variables.

Take Test
Q.63 Easy OOP in Java
What will be the output of the following code?
class Parent { void display() { System.out.println("Parent"); } }
class Child extends Parent { void display() { System.out.println("Child"); } }
public class Test { public static void main(String[] args) { Parent p = new Child(); p.display(); } }
A Child
B Parent
C Compilation Error
D Runtime Error
Correct Answer:  A. Child
EXPLANATION

This demonstrates runtime polymorphism. Even though p is a Parent reference, it points to a Child object, so the overridden display() method in Child class is executed.

Take Test
Q.64 Medium OOP in Java
Which statement about the 'protected' access modifier is correct?
A It allows access only within the same package
B It allows access within the same package and by subclasses in different packages
C It is equivalent to 'private'
D It allows access globally like 'public'
Correct Answer:  B. It allows access within the same package and by subclasses in different packages
EXPLANATION

'protected' members are accessible within the same package and also to subclasses in different packages. It provides more access than default but less than public.

Take Test
Q.65 Hard OOP in Java
A company's codebase has a scenario where multiple unrelated classes need to implement a contract with specific methods. Which design choice is best?
A Create an abstract parent class with abstract methods
B Create an interface with abstract method declarations
C Use composition instead of inheritance
D Create static utility methods in a common class
Correct Answer:  B. Create an interface with abstract method declarations
EXPLANATION

When unrelated classes need to implement a common contract, an interface is the best choice. Interfaces are specifically designed for this purpose, allowing multiple implementation without forcing an inheritance hierarchy.

Take Test
Q.66 Hard OOP in Java
When a static method is called on an instance of a class, what happens?
A The method is called on the instance object
B The method is called on the class, not the instance (though syntactically allowed)
C A compilation error occurs
D The instance data is used in the static method
Correct Answer:  B. The method is called on the class, not the instance (though syntactically allowed)
EXPLANATION

Static methods belong to the class, not instances. When called on an instance, Java internally calls the method on the class. Static methods cannot access instance variables or use 'this' keyword.

Take Test
Q.67 Easy OOP in Java
Which of the following correctly describes the relationship between a class and an interface?
A A class extends an interface
B An interface implements a class
C A class implements an interface
D Both are interchangeable terms
Correct Answer:  C. A class implements an interface
EXPLANATION

In Java, a class implements an interface. A class extends another class. An interface can extend another interface. This is the correct terminology and relationship structure.

Take Test
Q.68 Hard OOP in Java
A developer needs to create a class that cannot be extended and whose instances are immutable. Which keywords should be used?
A abstract and final
B final and ensure all fields are final
C private and synchronized
D static and volatile
Correct Answer:  B. final and ensure all fields are final
EXPLANATION

To prevent inheritance, use 'final' on the class. To make instances immutable, declare all fields as 'final' and ensure they are not modified after initialization. A classic example is the String class.

Take Test
Q.69 Medium OOP in Java
Which statement about interface implementation in Java is true?
A An interface can contain only abstract methods and no variables
B From Java 8 onwards, interfaces can have default methods and static methods
C A class implementing an interface must implement all its methods
D Both B and C are correct
Correct Answer:  D. Both B and C are correct
EXPLANATION

Java 8 introduced default and static methods in interfaces. Any class implementing an interface must provide implementations for all its abstract methods (unless the implementing class is abstract).

Take Test
Q.70 Hard OOP in Java
In Java, if a child class constructor does not explicitly call the parent class constructor using 'super()', what happens?
A A compilation error occurs
B The parent class constructor is automatically called (default no-arg constructor)
C The parent class constructor is never called
D The child class constructor must be declared as abstract
Correct Answer:  B. The parent class constructor is automatically called (default no-arg constructor)
EXPLANATION

Java automatically inserts a call to the parent class's no-arg constructor if 'super()' is not explicitly called. This ensures parent class initialization happens before child class initialization.

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