1. Which of the following is a characteristic of an abstract class?
A. It can be instantiated directly
B. It contains only abstract methods
C. It may have both abstract and concrete methods
D. It cannot inherit from other classes
Answer: C) It may have both abstract and concrete methods
Rationale: An abstract class can have abstract methods (without implementations)
and concrete methods (with implementations).
2. Which of the following is an example of a constructor in OOP?
A. A method that sets object properties
B. A method that creates a new instance of a class
C. A method that returns the value of an object
D. A method that ends the class execution
Answer: B) A method that creates a new instance of a class
,Rationale: A constructor is a special method used to initialize a new object when it
is created.
3. Which of the following OOP principles is used when a child class reuses
methods from a parent class?
A. Abstraction
B. Encapsulation
C. Inheritance
D. Polymorphism
Answer: C) Inheritance
Rationale: Inheritance allows a subclass to inherit methods and properties from a
superclass.
4. Which of the following is an example of a "has-a" relationship?
A. A student "is-a" person
B. A dog "has-a" collar
C. A vehicle "is-a" object
D. A class "has-a" method
, Answer: B) A dog "has-a" collar
Rationale: A "has-a" relationship is a composition, where one object contains
another object.
5. What is method overloading in OOP?
A. The ability of an object to take on many forms
B. Defining methods with the same name but different parameter types
C. Defining a method in multiple classes with different behavior
D. Reusing a method from a parent class
Answer: B) Defining methods with the same name but different parameter types
Rationale: Method overloading allows defining multiple methods with the same
name but different parameter types or counts.
6. What is the purpose of a destructor in object-oriented programming?
A. To initialize the state of an object
B. To destroy an object and free memory
C. To return a value from an object
D. To define methods for an object
A. It can be instantiated directly
B. It contains only abstract methods
C. It may have both abstract and concrete methods
D. It cannot inherit from other classes
Answer: C) It may have both abstract and concrete methods
Rationale: An abstract class can have abstract methods (without implementations)
and concrete methods (with implementations).
2. Which of the following is an example of a constructor in OOP?
A. A method that sets object properties
B. A method that creates a new instance of a class
C. A method that returns the value of an object
D. A method that ends the class execution
Answer: B) A method that creates a new instance of a class
,Rationale: A constructor is a special method used to initialize a new object when it
is created.
3. Which of the following OOP principles is used when a child class reuses
methods from a parent class?
A. Abstraction
B. Encapsulation
C. Inheritance
D. Polymorphism
Answer: C) Inheritance
Rationale: Inheritance allows a subclass to inherit methods and properties from a
superclass.
4. Which of the following is an example of a "has-a" relationship?
A. A student "is-a" person
B. A dog "has-a" collar
C. A vehicle "is-a" object
D. A class "has-a" method
, Answer: B) A dog "has-a" collar
Rationale: A "has-a" relationship is a composition, where one object contains
another object.
5. What is method overloading in OOP?
A. The ability of an object to take on many forms
B. Defining methods with the same name but different parameter types
C. Defining a method in multiple classes with different behavior
D. Reusing a method from a parent class
Answer: B) Defining methods with the same name but different parameter types
Rationale: Method overloading allows defining multiple methods with the same
name but different parameter types or counts.
6. What is the purpose of a destructor in object-oriented programming?
A. To initialize the state of an object
B. To destroy an object and free memory
C. To return a value from an object
D. To define methods for an object