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?
- Inheritance
- Encapsulation
- Polymorphism
- 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?
- An interface can declare constructors
- An abstract class can be instantiated directly with new
- An abstract class can have constructors, but an interface cannot
- 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();
- A
- B
- Compilation error
- 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
- Which OOP concept means bundling data and the methods that operate on it into…
- Method overloading (same method name, different parameter lists in one class)…
- Which OOP feature lets a single reference of a parent type call different…
- Which statement about constructors in Java is correct?
- A Car object contains an Engine object. This "has-a" relationship is best…
- What is the output of the following Java code?
- What is the output of the following Java code?
- Which statement about abstract classes and interfaces in Java is correct?
- In C++, how is the "diamond problem" (two copies of a common base class…
- Which pair of method declarations CANNOT both appear in the same Java class?
- What is printed when new C() is executed?
- What is the output of the following Java code?
- What is the output of the following Java code?
- What is the output of the following Java code?
- Which SOLID principle states that objects of a subclass should be usable…
- A Logger class keeps a list of log entries in a private field and offers only…
- Inside an instance method or constructor in Java, which keyword refers to the…
- Inheritance, as in 'SavingsAccount extends Account', models which kind of…
- Creating an object of a class, for example with new Student() in Java, is…
- Which OOP concept means exposing only the essential features of an object…
- What is the output of the following C++ program?
- What is the output of the following C++ program?
- What is the output of the following Python code?
- Which SOLID principle says a class should have only one reason to change?
- Which design pattern ensures that a class has only one instance and provides a…
- A House is made of Rooms, and the Rooms cannot exist without the House: when…
- What is the output of the following Java code?
- What is the output of the following C++ program?
- What is the output of the following Python code?
- What is the output of the following Java code?
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
- Pseudo-code: Trace loops, recursion and bitwise logic.
- C Programming: Output prediction, pointers and operators.
- Java: OOP, strings, collections and exceptions.
- Python: Data types, comprehensions and mutability.
- Data Structures: Arrays, stacks, queues, trees, graphs and hashing.
- Algorithms: Complexity, sorting, searching, recursion and DP.
- DBMS: Keys, normalisation, transactions and indexing.
- SQL: Joins, grouping, subqueries and query output.
- Operating Systems: Processes, scheduling, memory and deadlocks.
- Computer Networks: OSI/TCP-IP, protocols, addressing and ports.
- Software Engineering: SDLC, testing, agile and version control.
- Cloud & DevOps: Service models, containers, CI/CD and Linux.
- GenAI Basics: LLMs, tokens, prompting, embeddings and RAG.
Other subjects
- Quantitative Aptitude: Arithmetic, percentages, time and work, speed, probability and data interpretation: the numerical section of every fresher test.
- Logical Reasoning: Series, coding-decoding, arrangements, syllogisms and puzzles: the section that separates prepared candidates from the rest.
- Verbal Ability: Vocabulary, grammar, reading comprehension and sentence order: tested in nearly every IT services hiring exam.
- Python: Python quizzes by topic, from types and strings to classes and generators: output prediction and interview concepts.
- SQL: SQL quizzes by topic, from SELECT and joins to window functions: query output and concepts for analyst and developer roles.
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