40 Exam-Style Questions with Model Examiner Answers. Click "View Model Answer" to reveal the exact marking criteria.
Part 1: Foundational Questions (Questions 1 - 20)
Q01Easy
Define Object-Oriented Programming (OOP) and state two of its core goals.
Model Answer [5 Marks]: OOP is a programming paradigm based on the concept of "objects", which contain data (attributes/fields) and code (methods/behaviors). Two Core Goals: 1. Code Reusability (via inheritance/composition), 2. Modularity & Maintainability (via encapsulation).
Q02Easy
What is the distinction between a Class and an Object?
Model Answer [5 Marks]: A Class is a compile-time blueprint or user-defined data type describing properties and behaviors. An Object is a concrete runtime instance created on the heap taking up memory space.
Q03Easy
What does the term "Instantiation" mean in Java?
Model Answer [3 Marks]: Instantiation is the process of creating a concrete object instance of a class in heap memory using the new keyword.
Q04Easy
State the 4 major pillars of Object-Oriented Programming.
Define Encapsulation and explain how it is achieved in Java.
Model Answer [5 Marks]: Encapsulation is bundling data and methods into a single class while restricting direct access to instance fields. Achieved by: Declaring instance fields as private and exposing public getter and setter methods.
Q06Easy
What is Abstraction and why is it useful in software design?
Model Answer [4 Marks]: Abstraction hides internal complex implementation details and exposes only essential features. It reduces complexity and decouples interface from implementation.
Q07Easy
Differentiate between an IS-A relationship and a HAS-A relationship.
Model Answer [4 Marks]: IS-A: Represents Inheritance (e.g. Dog IS-A Animal). HAS-A: Represents Association/Aggregation/Composition (e.g. Car HAS-AN Engine).
Q08Easy
What is Polymorphism? State its two types in Java.
Model Answer [4 Marks]: Polymorphism allows one entity to take on multiple forms. Two Types: 1. Compile-Time Polymorphism (Method Overloading), 2. Runtime Polymorphism (Method Overriding).
Q09Easy
What is a Constructor in Java and what is its primary purpose?
Model Answer [3 Marks]: A special method sharing the class name with no return type. Its purpose is to initialize a newly created object's fields.
Q10Easy
What happens if a Java class defines no constructor explicitly?
Model Answer [3 Marks]: The Java compiler automatically inserts a default no-argument constructor.
Q11Easy
Explain Method Overloading.
Model Answer [3 Marks]: Defining multiple methods in the same class with the same name but different parameter lists (type, count, or order).
Q12Easy
Explain Method Overriding.
Model Answer [3 Marks]: A subclass providing a specific implementation of a method already defined in its superclass using the exact same signature.
Q13Easy
What is the role of the super keyword in Java?
Model Answer [3 Marks]: Refers to the immediate parent (superclass) object. Used to invoke parent constructors (super()) or parent methods.
Q14Easy
What is the role of the this keyword in Java?
Model Answer [3 Marks]: Refers to the current object instance executing the method. Resolves shadowing between instance fields and parameters.
Q15Easy
Does Java support Multiple Class Inheritance? Explain.
Model Answer [3 Marks]: No. Java does not allow a class to extend multiple classes to avoid the Diamond Problem ambiguity. Multiple interface implementation is allowed.
Q16Easy
What is an Abstract Class?
Model Answer [3 Marks]: A class declared with abstract that cannot be instantiated directly and may contain abstract methods without body.
Q17Easy
What is an Interface in Java?
Model Answer [3 Marks]: A blueprint contract declaring abstract methods that implementing classes must fulfill.
Q18Easy
Define Garbage Collection in Java.
Model Answer [3 Marks]: An automatic memory management process in JVM that reclaims heap memory occupied by unreferenced objects.
Q19Easy
What is the difference between Aggregation and Composition?
Model Answer [4 Marks]: Aggregation is a weak HAS-A relationship where child objects survive parent destruction. Composition is a strong PART-OF relationship where child lifetime is bound to parent.
Q20Easy
What is the DRY Principle in software engineering?
Model Answer [2 Marks]: "Don't Repeat Yourself" - avoiding code duplication by using inheritance, methods, or modular design.
Part 2: Medium / Applied Questions (Questions 21 - 30)
Q21Medium
Why does Encapsulation improve software security and maintainability? Give a concrete scenario.
Model Answer [5 Marks]: It prevents illegal external state modification. Scenario: In a BankAccount, if balance were public, any external code could set balance = -5000. Encapsulation forces access through withdraw(amt) which enforces invariant checks.
Q22Medium
Compare Method Overloading and Method Overriding in a structured table (3 differences).
Model Answer [6 Marks]: 1. Scope: Overloading is within same class; Overriding is between parent and child class. 2. Parameters: Overloading requires different parameters; Overriding requires identical parameters. 3. Binding: Overloading is compile-time (static); Overriding is runtime (dynamic).
Q23Medium
Explain how Polymorphism enables loose coupling in software architecture.
Model Answer [5 Marks]: By programming to an interface or abstract class reference rather than concrete implementations (e.g. List list = new ArrayList<>()). The client code depends only on the contract, allowing implementation swap without modifying client code.
Q24Medium
What is the Diamond Problem in C++ and how does Java avoid it?
Model Answer [5 Marks]: The Diamond Problem occurs in multiple class inheritance when Class D inherits from Class B and C, which both inherit from Class A. If B and C override a method from A, D faces ambiguity on which version to inherit. Java avoids this by disallowing multiple class inheritance.
Q25Medium
Can an Abstract class have a constructor? If yes, how is it invoked?
Model Answer [4 Marks]: Yes! An abstract class can have constructors. They cannot be invoked via new directly, but are executed when a subclass constructor calls super().
Q26Medium
Explain the concept of an Anonymous Inner Class in Java.
Model Answer [4 Marks]: An inner class declared without a name, instantiated in a single expression to override methods of an interface or class on the fly (commonly used for event listeners).
Q27Medium
Differentiate between Static Binding and Dynamic Binding.
Model Answer [5 Marks]: Static binding resolves method calls at compile-time (private, static, final methods). Dynamic binding resolves method calls at runtime based on the actual heap object instance type.
Q28Medium
What is an OOP Framework? Give two examples mentioned in lecture notes.
Model Answer [4 Marks]: A reusable set of libraries and design structures providing a foundational template for building software. Examples: Spring Framework, JavaFX.
Q29Medium
Explain how Covariant Return Types work in Java method overriding.
Model Answer [4 Marks]: In Java 5+, an overriding method in a subclass can return a subtype of the return type declared in the superclass method.
Q30Medium
What is the difference between Shallow Copy and Deep Copy of an object?
Model Answer [5 Marks]: Shallow copy duplicates primitive values but copies reference pointers to nested objects (sharing nested objects). Deep copy recursively duplicates all nested objects, creating independent memory instances.
Part 3: Hard / Examiner Trick Questions (Questions 31 - 40)
Q31Examiner Trick
TRICK: Can a static method be overridden in Java? Explain what happens if a subclass defines a static method with the exact same signature.
Model Answer [5 Marks]: NO! Static methods CANNOT be overridden. If a subclass defines the same static method, it is called Method Hiding. Method resolution depends on the reference type (compile-time), not the actual heap object.
Q32Examiner Trick
TRICK: Can a class be declared both abstract and final in Java?
Model Answer [4 Marks]: NO! Compile error. abstract requires subclasses to extend it, whereas final prevents subclasses from extending it. They are illegal contradictory modifiers.
Q33Examiner Trick
TRICK: Consider code: class Parent { public static void show() {} } class Child extends Parent { public void show() {} }. Will this compile?
Model Answer [5 Marks]: NO! Compile error. You cannot override a static method with an instance method (or vice versa).
Q34Examiner Trick
TRICK: Does an interface variable default to private if no modifier is specified?
Model Answer [4 Marks]: NO! All variables declared in an interface are implicitly public static final constants.
Q35Examiner Trick
TRICK: If a subclass constructor does NOT explicitly call super(...), what does the Java compiler do automatically?
Model Answer [4 Marks]: The compiler inserts a no-arg super() call as the first statement. If the parent class has no no-arg constructor, a compile error occurs!
Q36Examiner Trick
TRICK: Is Aggregation a sub-type of Composition, or is Composition a sub-type of Aggregation?
Model Answer [4 Marks]: Both Aggregation and Composition are specializations of Association. Composition is a stronger form of Aggregation where object lifetime is tightly coupled.
Q37Examiner Trick
TRICK: Can an inner class access private members of its outer enclosing class?
Model Answer [4 Marks]: YES! Inner classes have direct access to all private members and methods of their outer enclosing class.
Q38Examiner Trick
TRICK: What is the return type of a Constructor in Java?
Model Answer [4 Marks]: Constructors have NO return type (not even void). Specifying a return type turns it into a normal method!
Q39Examiner Trick
TRICK: Can you instantiate an Interface directly using new InterfaceName()?
Model Answer [4 Marks]: No, unless providing an Anonymous Inner Class implementation body inline (e.g. new Runnable() { public void run() {} }).
Q40Examiner Trick
TRICK: Why does changing a method's return type alone NOT create a valid method overload in Java?
Model Answer [5 Marks]: Because when a method is called without assigning its return value (e.g. doWork()), the compiler cannot determine which method to invoke based on return type alone. Overloading requires distinct parameter lists.