1. Which of the following is the correct definition of abstraction in OOP?
A. Hiding data and methods from external access
B. Defining the interface and leaving the implementation to the derived class
C. Reusing code from multiple classes
D. Overloading methods in the same class
Answer: B) Defining the interface and leaving the implementation to the derived
class
Rationale: Abstraction hides the complex implementation details and exposes only
the necessary parts of an object or class through a simplified interface.
2. What is the main advantage of using polymorphism in OOP?
A. It simplifies debugging
B. It increases the efficiency of the program
C. It allows a single method to work with different types of objects
D. It restricts access to data
Answer: C) It allows a single method to work with different types of objects
,Rationale: Polymorphism allows a method to perform different actions based on
the type of the object it is acting upon.
3. Which of the following is true about abstract methods in OOP?
A. They must be defined in the base class
B. They must have a body in the base class
C. They are not meant to be directly called
D. They cannot have parameters
Answer: C) They are not meant to be directly called
Rationale: Abstract methods provide a template for subclasses to implement but
cannot be called directly as they have no body.
4. Which of the following concepts does the "has-a" relationship describe?
A. Inheritance
B. Polymorphism
C. Composition
D. Encapsulation
Answer: C) Composition
, Rationale: The "has-a" relationship describes composition, where one object
contains references to other objects.
5. What is the main difference between an abstract class and an interface?
A. Abstract classes can have methods with implementations, while interfaces
cannot
B. Abstract classes are used for single inheritance, while interfaces allow multiple
inheritance
C. Interfaces can have only static methods, while abstract classes can have instance
methods
D. There is no difference
Answer: A) Abstract classes can have methods with implementations, while
interfaces cannot
Rationale: Abstract classes can have both abstract (unimplemented) and concrete
(implemented) methods, while interfaces can only declare abstract methods (prior
to Java 8).
6. Which of the following can cause an infinite recursion?
A. A constructor calling a parent constructor
A. Hiding data and methods from external access
B. Defining the interface and leaving the implementation to the derived class
C. Reusing code from multiple classes
D. Overloading methods in the same class
Answer: B) Defining the interface and leaving the implementation to the derived
class
Rationale: Abstraction hides the complex implementation details and exposes only
the necessary parts of an object or class through a simplified interface.
2. What is the main advantage of using polymorphism in OOP?
A. It simplifies debugging
B. It increases the efficiency of the program
C. It allows a single method to work with different types of objects
D. It restricts access to data
Answer: C) It allows a single method to work with different types of objects
,Rationale: Polymorphism allows a method to perform different actions based on
the type of the object it is acting upon.
3. Which of the following is true about abstract methods in OOP?
A. They must be defined in the base class
B. They must have a body in the base class
C. They are not meant to be directly called
D. They cannot have parameters
Answer: C) They are not meant to be directly called
Rationale: Abstract methods provide a template for subclasses to implement but
cannot be called directly as they have no body.
4. Which of the following concepts does the "has-a" relationship describe?
A. Inheritance
B. Polymorphism
C. Composition
D. Encapsulation
Answer: C) Composition
, Rationale: The "has-a" relationship describes composition, where one object
contains references to other objects.
5. What is the main difference between an abstract class and an interface?
A. Abstract classes can have methods with implementations, while interfaces
cannot
B. Abstract classes are used for single inheritance, while interfaces allow multiple
inheritance
C. Interfaces can have only static methods, while abstract classes can have instance
methods
D. There is no difference
Answer: A) Abstract classes can have methods with implementations, while
interfaces cannot
Rationale: Abstract classes can have both abstract (unimplemented) and concrete
(implemented) methods, while interfaces can only declare abstract methods (prior
to Java 8).
6. Which of the following can cause an infinite recursion?
A. A constructor calling a parent constructor