SCSJ2154 OBJECT ORIENTED PROGRAMMING
EXAM with Questions and Answers/Plus a
Rationale Updated 2026 A+/Instant Download
PDF
EXAM COVERAGE
1. Object-Oriented Fundamentals (Classes, Objects, Methods, Constructors)
2. Encapsulation and Data Hiding
3. Inheritance and Polymorphism
4. Abstract Classes and Interfaces
5. Exception Handling
6. Java Collections Framework
7. Graphical User Interface (GUI) Event Handling
8. Generics and Type Safety
9. Design Principles (SOLID, Association, Aggregation, Composition)
1. A developer is designing a system where a 'Library' class contains many 'Book' objects. If the
'Book' objects can exist independently of the 'Library', which relationship should be
implemented?
A. Composition
B. Aggregation
C. Generalization
, D. Inheritance
CORRECT ANSWER : B
Rationale: Aggregation represents a "has-a" relationship where the parts can exist
independently of the whole. Composition (A) implies that the parts cannot exist without the
container, and Generalization/Inheritance (C, D) describe "is-a" relationships.
2. Consider the following Java snippet: public class A { public void display() {
System.out.println("A"); } } and public class B extends A { public
void display() { System.out.println("B"); } } . If a program executes A obj
= new B(); obj.display();, what is the output?
A. A
B. B
C. Compilation Error
D. Runtime Error
CORRECT ANSWER : B
Rationale: This demonstrates dynamic method dispatch (polymorphism). Even though the
reference type is A, the object type is B, so the overridden method in class B is invoked at
runtime.
3. Which of the following best describes the purpose of an Interface in Java?
A. To provide a partial implementation of methods for subclasses.
B. To define a contract for behavior that multiple unrelated classes can implement.
C. To allow multiple inheritance of state (fields).
D. To prevent a class from being instantiated.
CORRECT ANSWER : B
Rationale: Interfaces define a set of methods that a class must implement, enabling polymorphic
behavior across unrelated class hierarchies. Option A describes Abstract Classes, while Java
does not support multiple inheritance of state.
4. You need to ensure that an instance variable is only accessible within its own class. Which
modifier should you use?
, A. public
B. protected
C. private
D. package-private
CORRECT ANSWER : C
Rationale: The private modifier provides the highest level of encapsulation by restricting
access solely to the class where the variable is defined. Protected and package-private allow
access to subclasses or classes in the same package.
5. What is the primary advantage of using Generics in the Java Collections Framework?
A. Increased memory usage.
B. Compile-time type safety.
C. Faster execution speed at runtime.
D. Elimination of the need for interfaces.
CORRECT ANSWER : B
Rationale: Generics allow you to specify the type of objects a collection can hold, catching type
mismatch errors at compile time rather than causing ClassCastException at runtime.
6. In the context of Exception Handling, what is the purpose of the finally block?
A. To catch specific exceptions.
B. To ensure that critical cleanup code is executed regardless of whether an exception
occurred.
C. To handle errors that the catch block cannot process.
D. To terminate the program immediately.
CORRECT ANSWER : B
Rationale: The finally block is guaranteed to execute after the try-catch sequence, making it
the ideal location for closing resources like database connections or file streams.
7. Which of the following is a violation of the Liskov Substitution Principle?
, A. A subclass providing an overridden method that fulfills the superclass contract.
B. A subclass throwing a new, checked exception that the superclass methods do not
declare.
C. A subclass adding new methods that do not affect the behavior of superclass methods.
D. A class implementing an interface.
CORRECT ANSWER : B
Rationale: Liskov Substitution states that objects of a superclass should be replaceable with
objects of its subclasses without altering the program's correctness. Throwing unexpected
exceptions breaks the contract expected by the client code.
8. When a class contains a reference to another class, this is known as:
A. Inheritance
B. Association
C. Overloading
D. Encapsulation
CORRECT ANSWER : B
Rationale: Association is the basic relationship where two classes are linked, usually through an
instance variable. Inheritance is an "is-a" relationship, and encapsulation refers to data hiding.
9. Which keyword is used to prevent a class from being inherited?
A. static
B. abstract
C. final
D. private
CORRECT ANSWER : C
Rationale: The final keyword, when applied to a class, signifies that it cannot be extended. An
abstract class is specifically designed to be extended.
10. What occurs if a programmer defines a constructor in a class?
EXAM with Questions and Answers/Plus a
Rationale Updated 2026 A+/Instant Download
EXAM COVERAGE
1. Object-Oriented Fundamentals (Classes, Objects, Methods, Constructors)
2. Encapsulation and Data Hiding
3. Inheritance and Polymorphism
4. Abstract Classes and Interfaces
5. Exception Handling
6. Java Collections Framework
7. Graphical User Interface (GUI) Event Handling
8. Generics and Type Safety
9. Design Principles (SOLID, Association, Aggregation, Composition)
1. A developer is designing a system where a 'Library' class contains many 'Book' objects. If the
'Book' objects can exist independently of the 'Library', which relationship should be
implemented?
A. Composition
B. Aggregation
C. Generalization
, D. Inheritance
CORRECT ANSWER : B
Rationale: Aggregation represents a "has-a" relationship where the parts can exist
independently of the whole. Composition (A) implies that the parts cannot exist without the
container, and Generalization/Inheritance (C, D) describe "is-a" relationships.
2. Consider the following Java snippet: public class A { public void display() {
System.out.println("A"); } } and public class B extends A { public
void display() { System.out.println("B"); } } . If a program executes A obj
= new B(); obj.display();, what is the output?
A. A
B. B
C. Compilation Error
D. Runtime Error
CORRECT ANSWER : B
Rationale: This demonstrates dynamic method dispatch (polymorphism). Even though the
reference type is A, the object type is B, so the overridden method in class B is invoked at
runtime.
3. Which of the following best describes the purpose of an Interface in Java?
A. To provide a partial implementation of methods for subclasses.
B. To define a contract for behavior that multiple unrelated classes can implement.
C. To allow multiple inheritance of state (fields).
D. To prevent a class from being instantiated.
CORRECT ANSWER : B
Rationale: Interfaces define a set of methods that a class must implement, enabling polymorphic
behavior across unrelated class hierarchies. Option A describes Abstract Classes, while Java
does not support multiple inheritance of state.
4. You need to ensure that an instance variable is only accessible within its own class. Which
modifier should you use?
, A. public
B. protected
C. private
D. package-private
CORRECT ANSWER : C
Rationale: The private modifier provides the highest level of encapsulation by restricting
access solely to the class where the variable is defined. Protected and package-private allow
access to subclasses or classes in the same package.
5. What is the primary advantage of using Generics in the Java Collections Framework?
A. Increased memory usage.
B. Compile-time type safety.
C. Faster execution speed at runtime.
D. Elimination of the need for interfaces.
CORRECT ANSWER : B
Rationale: Generics allow you to specify the type of objects a collection can hold, catching type
mismatch errors at compile time rather than causing ClassCastException at runtime.
6. In the context of Exception Handling, what is the purpose of the finally block?
A. To catch specific exceptions.
B. To ensure that critical cleanup code is executed regardless of whether an exception
occurred.
C. To handle errors that the catch block cannot process.
D. To terminate the program immediately.
CORRECT ANSWER : B
Rationale: The finally block is guaranteed to execute after the try-catch sequence, making it
the ideal location for closing resources like database connections or file streams.
7. Which of the following is a violation of the Liskov Substitution Principle?
, A. A subclass providing an overridden method that fulfills the superclass contract.
B. A subclass throwing a new, checked exception that the superclass methods do not
declare.
C. A subclass adding new methods that do not affect the behavior of superclass methods.
D. A class implementing an interface.
CORRECT ANSWER : B
Rationale: Liskov Substitution states that objects of a superclass should be replaceable with
objects of its subclasses without altering the program's correctness. Throwing unexpected
exceptions breaks the contract expected by the client code.
8. When a class contains a reference to another class, this is known as:
A. Inheritance
B. Association
C. Overloading
D. Encapsulation
CORRECT ANSWER : B
Rationale: Association is the basic relationship where two classes are linked, usually through an
instance variable. Inheritance is an "is-a" relationship, and encapsulation refers to data hiding.
9. Which keyword is used to prevent a class from being inherited?
A. static
B. abstract
C. final
D. private
CORRECT ANSWER : C
Rationale: The final keyword, when applied to a class, signifies that it cannot be extended. An
abstract class is specifically designed to be extended.
10. What occurs if a programmer defines a constructor in a class?