Unit 3: Relationships - Inheritance

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

D) The process of modifying class attributes

8. What is the purpose of a constructor in Object-Oriented Programming?


A) To create static members
B) To initialize the state of an object
C) To destroy objects
D) To modify class attributes

9. What is the term for the process of destroying objects in Object-Oriented Programming?
A) Construction
B) Destructive method
C) Destructor
D) Garbage collection

10. When identifying classes in Object-Oriented Programming, what are candidates for classes?
A) Methods
B) Attributes
C) Shared behavior and state
D) Message passing strategies

Unit 3: Relationships – Inheritance


1. In Object-Oriented Programming, what is the primary purpose of inheritance?
A) To create new objects
B) To define the state and behavior of an object
C) To enable code reuse and establish a hierarchical relationship
D) To encapsulate data

2. What term best describes the relationship between a subclass and its superclass in inheritance?
A) Has-a
B) Is-a
C) Association
D) Aggregation

3. Which of the following is an example of an "is-a" relationship?


A) A car has an engine
B) A dog is a mammal
C) A library is composed of books
D) A person owns a house

4. What is association in Object-Oriented Programming?


A) A relationship where one class is a part of another class
B) A relationship where objects of one class are connected to objects of another class
C) A relationship between a superclass and its subclass
D) A relationship between static members of a class

5. What term is used to describe a stronger form of association where one class "owns" objects of
another class?
A) Inheritance
B) Aggregation
C) Composition
D) Encapsulation

6. What is aggregation in Object-Oriented Programming?


A) A relationship where one class inherits from another class
B) A relationship where objects of one class are part of objects of another class
C) A relationship between an interface and its implementations
D) A relationship between static members of a class

7. What is an abstract class in Object-Oriented Programming?


A) A class that cannot be instantiated but can be subclassed
B) A class that is fully implemented and can be instantiated
C) A class that contains only abstract methods
D) A class that cannot have any subclasses

8. What is an interface in Object-Oriented Programming?


A) A concrete class with no implementation details
B) A blueprint for a class that defines a set of methods that must be implemented
C) A class that cannot have any methods
D) A class that cannot be instantiated or subclassed

9. Which of the following is NOT a type of inheritance?


A) Single inheritance
B) Multiple inheritance
C) Multilevel inheritance
D) Horizontal inheritance

10. Which relationship in Object-Oriented Programming allows for the reusability of code by enabling
a subclass to inherit features from a superclass?
A) Aggregation
B) Association
C) Inheritance
D) Composition

Unit 4: Polymorphism
1. What is polymorphism in Object-Oriented Programming?
A) The process of hiding the implementation details of an object's state
B) The process of creating duplicate objects
C) The ability of a method to do different things based on the object it is acting upon
D) The process of defining multiple constructors for a class

2. Which of the following best describes method overriding in C++?


A) Providing multiple implementations of the same method within a class
B) Redefining a method in a subclass with the same signature as a method in the superclass
C) Providing different implementations of a method with different signatures
D) Creating a new method with the same name but different parameters

3. What is method overloading in C++?


A) Providing multiple implementations of the same method within a class
B) Redefining a method in a subclass with the same signature as a method in the superclass
C) Providing different implementations of a method with different signatures
D) Creating a new method with the same name but different parameters

4. In method overloading, what determines which version of a method will be called?


A) The return type of the method
B) The name of the method
C) The number and types of parameters passed to the method
D) The access modifier of the method

5. What is static polymorphism?


A) Polymorphism that is resolved at compile time
B) Polymorphism that is resolved at runtime
C) Polymorphism that involves method overloading
D) Polymorphism that involves method overriding

6. Which type of polymorphism is achieved through method overloading?


A) Static polymorphism
B) Dynamic polymorphism
C) Compile-time polymorphism
D) Runtime polymorphism

7. What is runtime polymorphism?


A) Polymorphism that is resolved at compile time
B) Polymorphism that is resolved at runtime
C) Polymorphism that involves method overloading
D) Polymorphism that involves method overriding

8. Which keyword is used to denote method overriding in C++?


A) override
B) virtual
C) super
D) @Override

9. In C++, can a subclass method override a superclass method with a broader access modifier?
A) Yes
B) No

10. Which of the following statements about polymorphism is true?


A) Polymorphism is achieved only through inheritance
B) Polymorphism allows objects of different types to be treated as objects of a single type
C) Polymorphism is limited to method overloading
D) Polymorphism is resolved at compile-time only
Unit 5:
1. Which of the following best describes a String in C++?
A) A primitive data-type
B) An array of characters
C) An object that represents a sequence of characters
D) A class that cannot be instantiated

2. In C++, how are exceptions handled?


A) Using if-else statements
B) Using try-catch blocks
C) Using loops
D) Using switch statements

3. What is the purpose of multi-threading in C++?


A) To improve code readability
B) To allow for parallel execution of tasks
C) To simplify exception handling
D) To enforce data encapsulation

4. Which of the following is NOT a data collection in C++?


A) ArrayList
B) HashMap
C) String
D) LinkedList

5. In a Library Management System, what data collection might be used to store information about
books and their availability?
A) ArrayList
B) HashSet
C) TreeMap
D) LinkedList

6. What is an ATM (Automated Teller Machine) an example of in terms of Object-Oriented


Programming?
A) A data collection
B) A multi-threaded application
C) A case study
D) An exceptional handling scenario

7. How are exceptions typically handled in ATM systems?


A) By printing the exception message to the console
B) By terminating the program
C) By catching the exception and displaying an error message to the user
D) By ignoring the exception and continuing execution

8. What is the purpose of multi-threading in the context of an ATM system?


A) To allow multiple users to access the system simultaneously
B) To improve the security of the system
C) To simplify exception handling
D) To enforce data encapsulation

9. Which data collection in C++ stores elements in key-value pairs?


A) ArrayList
B) HashMap
C) TreeSet
D) Stack

10. In a Library Management System, what data collection might be used to store information about
library members and their borrowed books?
A) HashSet
B) LinkedList
C) TreeMap
D) HashMap

You might also like