Java Programming — OOP in Java
Java OOP, collections, multithreading
46 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 46 questions in OOP in Java
Q.1 Medium OOP in Java
In Java, when you override a method from a parent class, which of the following is NOT a valid reason to use the @Override annotation?
A To enable compile-time checking for correct method signature
B To improve code readability and maintainability
C To automatically invoke the parent class method implementation
D To catch errors if the parent method is removed or signature changes
Correct Answer:  C. To automatically invoke the parent class method implementation
EXPLANATION

The @Override annotation helps verify that you are correctly overriding a parent method and improves code clarity, but it does NOT automatically invoke the parent class method. You must use super.methodName() for that. @Override is purely a compile-time marker for verification purposes.

Take Test
Q.2 Medium OOP in Java
In Java, a class can implement multiple interfaces but can extend only one class. This design choice primarily supports which principle?
A Single Responsibility Principle
B Liskov Substitution Principle
C Avoiding diamond problem in single inheritance
D Interface Segregation Principle
Correct Answer:  C. Avoiding diamond problem in single inheritance
EXPLANATION

Multiple inheritance of implementation can cause the diamond problem. Java avoids this by allowing single class inheritance but multiple interface implementation.

Take Test
Q.3 Medium OOP in Java
Which of the following statements about 'this' keyword in Java is INCORRECT?
A 'this' can be used to refer to the current object
B 'this' can be used to invoke another constructor of the same class
C 'this' can be used in static methods
D 'this' can be used to return the current object
Correct Answer:  C. 'this' can be used in static methods
EXPLANATION

'this' cannot be used in static methods because static methods are class-level and don't have an instance context. 'this' always refers to an instance.

Take Test
Q.4 Medium OOP in Java
What will be printed when this code executes?
class A { int x = 5; }
class B extends A { int x = 10; }
public class Test {
public static void main(String[] args) {
A a = new B();
System.out.println(a.x);
}
}
A 5
B 10
C Compilation error
D Runtime exception
Correct Answer:  A. 5
EXPLANATION

Variable shadowing occurs here. 'a' is of type A, so a.x refers to A's variable x which is 5. Variables are not overridden, only methods are.

Take Test
Q.5 Medium OOP in Java
Consider a scenario where you have an interface Shape with a method calculateArea(). You implement this in classes Circle and Rectangle. Which OOP concept is being demonstrated?
A Encapsulation
B Abstraction
C Polymorphism
D Both Abstraction and Polymorphism
Correct Answer:  D. Both Abstraction and Polymorphism
EXPLANATION

The interface provides abstraction by hiding implementation details. Multiple classes implementing the same interface method demonstrates polymorphism (many forms).

Take Test
Advertisement
Q.6 Medium OOP in Java
In Java, if a parent class has a method void display() and a child class overrides it as void display(int x), what is this called?
A Method Overriding
B Method Overloading
C Method Shadowing
D Invalid - compilation error
Correct Answer:  B. Method Overloading
EXPLANATION

This is method overloading, not overriding, because the method signature is different (different parameters). Overriding requires the same signature.

Take Test
Q.7 Medium OOP in Java
What is the output of this code?
class Test {
static int x = 10;
public static void main(String[] args) {
System.out.println(x++);
}
}
A 10
B 11
C Compilation error
D Runtime exception
Correct Answer:  A. 10
EXPLANATION

The post-increment operator (x++) returns the value before incrementing. So it prints 10, and then x becomes 11.

Take Test
Q.8 Medium OOP in Java
Consider a class hierarchy: Animal -> Dog -> Puppy. A Puppy reference can access which of the following?
A Only Puppy methods
B Puppy and Dog methods, but not Animal methods
C Puppy, Dog, and Animal methods
D Only methods declared as public
Correct Answer:  C. Puppy, Dog, and Animal methods
EXPLANATION

Through inheritance, a Puppy reference can access all non-private methods from Puppy, Dog, and Animal classes through the inheritance chain.

Take Test
Q.9 Medium OOP in Java
Which statement about Java interfaces is INCORRECT according to 2024 specifications?
A Interfaces can have static methods
B Interfaces can have default methods
C Interfaces can have private methods
D Interfaces can be instantiated directly
Correct Answer:  D. Interfaces can be instantiated directly
EXPLANATION

Interfaces cannot be instantiated directly. Since Java 8, interfaces can have static and default methods, and since Java 9, they can have private methods.

Take Test
Q.10 Medium OOP in Java
What is the correct way to call a parent class constructor from a child class?
A parent();
B super();
C this.parent();
D ParentClass();
Correct Answer:  B. super();
EXPLANATION

The super() keyword is used to call the parent class constructor. It must be the first statement in the child class constructor.

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