IKM Object-Oriented Programming Principles — Questions and Answers
Question 1: What is encapsulation in OOP?
- Inheriting methods
- Bundling data and methods while restricting access to internal state (Correct answer)
- Creating multiple objects
- Using interfaces
Correct answer: Bundling data and methods while restricting access to internal state
Encapsulation bundles data and methods within a class, hiding internal implementation.
Access modifiers (private, protected, public) control visibility. Private fields accessed through getters/setters allow validation and future implementation changes without breaking client code.
Question 2: What is the difference between overloading and overriding?
- Overloading changes return types
- Overloading uses different parameters in same class; overriding redefines a parent method in subclass (Correct answer)
- They are the same
- Overloading is compile-time only
Correct answer: Overloading uses different parameters in same class; overriding redefines a parent method in subclass
Overloading provides same-name methods with different parameters; overriding redefines inherited methods.
Overloading is compile-time polymorphism. Overriding is runtime polymorphism where a subclass provides specific implementation of a parent method with the same signature.
Question 3: What is an abstract class?
- Class with no methods
- Class that cannot be instantiated and may contain abstract methods (Correct answer)
- Class with only static methods
- Class that auto garbage collects
Correct answer: Class that cannot be instantiated and may contain abstract methods
Abstract classes cannot be instantiated and may have abstract methods subclasses must implement.
Abstract classes can have both abstract methods (no body) and concrete methods. They can have instance variables and constructors. A class can extend only one abstract class but implement multiple interfaces.
Question 4: What is the Liskov Substitution Principle?
- Single responsibility
- Subclass objects should be replaceable for superclass objects without breaking the program (Correct answer)
- Depend on abstractions
- Open for extension
Correct answer: Subclass objects should be replaceable for superclass objects without breaking the program
LSP states subclass objects must work wherever superclass objects are expected.
A classic violation: Square extends Rectangle but setting width changes both dimensions. LSP requires preconditions cannot be strengthened and postconditions cannot be weakened in subtypes.
Question 5: What is composition over inheritance?
- Using constructors over factories
- Favoring has-a relationships over is-a relationships for code reuse (Correct answer)
- Composing interfaces
- Multiple inheritance
Correct answer: Favoring has-a relationships over is-a relationships for code reuse
Composition uses contained objects for behavior rather than extending classes.
Inheritance creates tight coupling. Composition delegates to contained objects that can be swapped at runtime. The Strategy pattern formalizes this. Go and Rust use composition exclusively.
Question 6: What is the purpose of an interface in OOP?
- Store global variables
- Define a contract of methods implementing classes must provide (Correct answer)
- Manage memory
- Handle logging
Correct answer: Define a contract of methods implementing classes must provide
An interface defines method signatures that implementing classes must provide.
A class can implement multiple interfaces. Interfaces support Dependency Inversion: high-level modules depend on abstractions. The Interface Segregation Principle advises keeping interfaces small.
Question 7: What is polymorphism in OOP?
- Multiple constructors
- Different objects respond to the same method call differently (Correct answer)
- Hiding implementation details
- Creating objects from templates
Correct answer: Different objects respond to the same method call differently
Polymorphism allows different classes to provide their own implementation of shared methods.
Forms include subtype (overriding), parametric (generics), and ad-hoc (overloading). Runtime polymorphism uses vtables for dynamic dispatch.
Question 8: What is the Single Responsibility Principle?
- One method per class
- A class should have only one reason to change (Correct answer)
- Instantiate once
- No dependencies
Correct answer: A class should have only one reason to change
SRP means each class should have only one job or responsibility.
A class handling both authentication and email sending has two responsibilities. SRP reduces coupling, improves testability, and applies at all levels: methods, classes, and modules.
Question 9: What is a design pattern?
- Specific algorithm
- Reusable solution template for common design problems (Correct answer)
- Language syntax rule
- Database schema
Correct answer: Reusable solution template for common design problems
Design patterns are general, reusable solutions to commonly occurring problems.
GoF cataloged 23 patterns in three categories: Creational (Factory, Singleton), Structural (Adapter, Decorator), and Behavioral (Observer, Strategy).
Question 10: What is the Observer design pattern?
- Creates object copies
- Subject notifies dependents of state changes (Correct answer)
- Sequential collection access
- Step-by-step object building
Correct answer: Subject notifies dependents of state changes
Observer defines a one-to-many dependency where state changes trigger notifications.
Implements publish-subscribe. The subject maintains observers and calls their update method. Used in event handling, MVC architecture, and reactive programming.
Question 11: What is the difference between shallow and deep copy?
- Shallow is faster
- Shallow copies references; deep copy recursively duplicates all nested objects (Correct answer)
- Shallow is primitives only
- No meaningful difference
Correct answer: Shallow copies references; deep copy recursively duplicates all nested objects
Shallow copy shares references to nested objects; deep copy creates independent copies at every level.
With shallow copy, modifying nested objects affects both copies. In Python, copy.copy() is shallow, copy.deepcopy() is deep. In JS, structuredClone() provides deep copying.
Question 12: What is the Dependency Inversion Principle?
- Low-level depends on high-level
- High-level modules should depend on abstractions, not low-level modules (Correct answer)
- Constructor injection only
- Invert to prevent circular refs
Correct answer: High-level modules should depend on abstractions, not low-level modules
DIP states both high and low-level modules should depend on abstractions.
Instead of PaymentService depending on StripeProcessor, both depend on a PaymentGateway interface. Enables swapping implementations and testing with mocks.
Question 13: A Square class extends Rectangle, and Square.setWidth() also changes the height, breaking client code that expects width and height to vary independently. Which principle is violated?
- Single Responsibility Principle
- Open/Closed Principle
- Liskov Substitution Principle (Correct answer)
- Interface Segregation Principle
Correct answer: Liskov Substitution Principle
LSP requires subtypes to be usable wherever the base type is expected without altering correct program behavior.
Question 14: A developer changes an internal method of a base class, and several subclasses that overrode related methods silently break. What is this problem called?
- Fragile base class problem (Correct answer)
- Diamond problem
- Object slicing
- Yo-yo problem
Correct answer: Fragile base class problem
The fragile base class problem occurs when seemingly safe base-class changes break subclasses that depend on its implementation details.
Question 15: In Java, what may an overriding method's return type be compared to the overridden method's return type?
- Any type, as long as the parameters match
- Only the exact same type
- A supertype of the original return type
- A subtype of the original return type (Correct answer)
Correct answer: A subtype of the original return type
Java supports covariant return types, so an override may return a more specific subtype.
Question 16: Which C++ feature ensures that a class inheriting from two classes with a common base gets only one shared copy of that base?
- Abstract base classes
- Virtual inheritance (Correct answer)
- Friend classes
- Pure virtual functions
Correct answer: Virtual inheritance
Declaring the base with 'virtual' inheritance resolves the diamond problem by sharing one base subobject.
Question 17: In Java, a subclass declares a static method with the same signature as a static method in its parent. Given Parent p = new Child(); p.staticMethod(); which version runs?
- Parent's version, because static methods are hidden, not overridden (Correct answer)
- Child's version, because of dynamic dispatch
- Both versions, parent first
- Compilation fails due to duplicate signatures
Correct answer: Parent's version, because static methods are hidden, not overridden
Static methods are bound at compile time based on the declared reference type, which is called method hiding.
Question 18: A Printer class must implement a MultiFunctionDevice interface and throw UnsupportedOperationException for fax() and scan(). Which principle does this design violate?
- Dependency Inversion Principle
- Liskov Substitution Principle only
- Interface Segregation Principle (Correct answer)
- Don't Repeat Yourself
Correct answer: Interface Segregation Principle
ISP states clients should not be forced to depend on methods they do not use, so the fat interface should be split.
Question 19: Which call chain most clearly violates the Law of Demeter?
- this.calculateTotal()
- order.getCustomer().getAddress().getZipCode() (Correct answer)
- parameter.validate()
- new Invoice(order).print()
Correct answer: order.getCustomer().getAddress().getZipCode()
The Law of Demeter says an object should talk only to its immediate collaborators, not reach through a chain of objects.
What is encapsulation in OOP?
What Practice Test Geeks adds beyond an AI chat for IKM
An AI chatbot can quiz you, but it can't reproduce the exam conditions or keep your record. Here you get:
- A timed, full-length IKM mock exam — 40 questions in 60 minutes with a 70% pass mark, modeled on the official exam's question count and time limit, followed by a score report broken down by exam domain.
- A fixed IKM question bank: the same test every attempt, so your score is comparable from one try to the next instead of changing with every regenerated quiz.
- Progress saved on your device: completed tests, scores and missed questions stay in My Progress, so you can retake only what you got wrong.
- A printable IKM cheat sheet you can print or save as a PDF.
- IKM flashcards built from the same question bank.
Practice questions written with AI assistance and published by Nathan Beja, founder of Practice Test Geeks. They are not real exam questions. Exam facts are checked against the official sources linked below. Editorial policy
Sources & references
Exam facts on this page (fees, format, dates, passing scores) are checked against these official sources; the date is our last check. Editorial policy
- ikmnet.com — Test delivery, passing score · verified Oct 2026
- online.ikmnet.com — Eligibility, exam format, retake policy, score release, time limit · verified Oct 2026