Object-Oriented Programming questions and answers

Encapsulation, inheritance, polymorphism, abstraction. Practise object-oriented programming questions from the technical & programming section of placement tests, with a worked explanation after every answer. Practice is free and needs no sign-up.

Sample object-oriented programming questions with worked answers

Question 1

Which OOP concept means bundling data and the methods that operate on it into a single unit, while restricting direct access to the data?

  1. Inheritance
  2. Encapsulation
  3. Polymorphism
  4. Abstraction

Answer: B. Encapsulation

Explanation: Encapsulation wraps data and behaviour together in a class and hides the internal state behind methods, for example private fields with public getters and setters.

Question 2

Which statement about abstract classes and interfaces in Java is correct?

  1. An interface can declare constructors
  2. An abstract class can be instantiated directly with new
  3. An abstract class can have constructors, but an interface cannot
  4. A Java class can extend more than one abstract class

Answer: C. An abstract class can have constructors, but an interface cannot

Explanation: An abstract class can define constructors, which run when a subclass object is created. Interfaces cannot have constructors. Java allows only single class inheritance, and abstract classes cannot be instantiated.

Question 3

What is the output of the following Java code?

class A {
    static void show() { System.out.println("A"); }
}
class B extends A {
    static void show() { System.out.println("B"); }
}
// in main:
A obj = new B();
obj.show();
  1. A
  2. B
  3. Compilation error
  4. Runtime error

Answer: A. A

Explanation: Static methods are not overridden; they are hidden. A static call is resolved at compile time from the reference type (A), so A.show() runs and prints "A".

All 30 object-oriented programming questions with answers

Object-Oriented Programming: common questions

What are object-oriented programming questions?

Encapsulation, inheritance, polymorphism, abstraction. They appear in the technical & programming section of many placement tests.

Where can I practise object-oriented programming questions with answers for free?

Right here on LogicWiz Exams. Every object-oriented programming question has a worked explanation after you answer. Practice is free and needs no sign-up.

How should I practise object-oriented programming?

Start with easy questions, then move to medium and hard. Read the explanation after each answer, and come back to the ones you missed.

Start practising

On this page you can start a fresh set of object-oriented programming questions, choose easy, medium or hard, and time yourself if you want to. Or practise the whole subject: Technical & Programming practice.

More technical & programming topics

Other subjects

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge · Test from a job description · LogicWiz Open: free team quiz · Free interview prep