Class Activity 1
Class Activity 1
Class Activity 1
a) Object-Oriented Protocol
b) Out-of-Order Processing
c) Object-Oriented Programming
2. Which concept in OOP allows a class to inherit properties and behaviors from another class?
a) Composition
b) Aggregation
c) Inheritance
d) Polymorphism
c) A process of inheritance
4. Which OOP principle allows a single class to implement methods with the same name but different
parameters?
a) Abstraction
b) Encapsulation
c) Inheritance
d) Polymorphism
c) A mathematical equation
d) A programming keyword
6. Which OOP concept helps prevent code duplication and promotes reusability?
a) Polymorphism
b) Encapsulation
c) Inheritance
d) Composition
a) Encapsulation
b) Abstraction
c) Polymorphism
d) Inheritance
9. Which OOP concept allows you to bundle data and methods that operate on that data into a single
unit?
a) Inheritance
b) Encapsulation
c) Polymorphism
d) Abstraction
10. Which keyword is used to create an instance of a class in most programming languages?
a) new
b) create
c) instance
d) object
12. Which term refers to the process of defining a new class based on an existing class?
a) Abstraction
b) Encapsulation
c) Inheritance
d) Polymorphism
a) Defining a new method with the same name and parameters in a subclass
14. Which OOP principle involves grouping related data and functions into a single unit?
a) Encapsulation
b) Abstraction
c) Polymorphism
d) Inheritance
15. In OOP, what does the term 'superclass' refer to?
17. Which OOP concept allows you to define a relationship between objects where one object contains
another?
a) Composition
b) Aggregation
c) Encapsulation
d) Inheritance
18. Which term refers to the ability of a class to inherit properties and behaviors from multiple classes?
a) Multiple inheritance
b) Multilevel inheritance
c) Hierarchical inheritance
d) Single inheritance
20. Which OOP principle allows you to define a common interface for a group of related classes?
a) Inheritance
b) Encapsulation
c) Abstraction
d) Polymorphism
a) Inheritance
b) Abstraction
c) Instantiation
d) Polymorphism
a) Defining multiple methods with the same name but different parameters
24. Which OOP concept allows you to implement the "is-a" relationship between classes?
a) Composition
b) Aggregation
c) Inheritance
d) Encapsulation
25. What is the term for a class that inherits properties and behaviors from another class?
a) Child class
b) Subclass
c) Superclass
d) Derived class
26. Which OOP concept allows you to define a template for creating objects and includes both data and
behavior?
a) Method
b) Function
c) Class
d) Instance
27. What is the main advantage of using OOP over procedural programming?
d) Simpler syntax
Here are scenarios where inheritance and polymorphism can be applied in programming:
1. Shapes Hierarchy:
Imagine you're designing a drawing application. You could create a base class called `Shape`, and then
derive classes like `Circle`, `Rectangle`, and `Triangle` from it. Each derived class would inherit common
properties and methods from the base class, such as `calculateArea()`. This way, you can treat all shapes
uniformly using polymorphism, allowing you to call methods like `calculateArea()` on any shape object
without worrying about its specific type.
2. Vehicle Types:
Suppose you're working on a simulation of different types of vehicles. You could have a base class
`Vehicle` and then derive classes like `Car`, `Truck`, and `Motorcycle` from it. Each vehicle type might
have its own unique properties and methods, like `calculateFuelEfficiency()`. With polymorphism, you
can create a list of `Vehicle` objects and iterate through them, calling methods like `startEngine()`
without needing to know the specific vehicle type.
3. Banking System:
In a banking application, you might have a base class `Account` and derived classes like `SavingsAccount`
and `CheckingAccount`. Each account type would have methods like `deposit()` and `withdraw()`. By
using polymorphism, you can treat all account types uniformly, allowing you to perform common
operations across different account types without knowing their exact implementations.
4. Multimedia Players:
Imagine creating a multimedia player that can handle different types of media files: audio and video. You
could create a base class `Media` and then derived classes like `Audio` and `Video`. Each media type
might have methods like `play()` and `pause()`. By using polymorphism, you can play and control both
audio and video files using the same interface, regardless of their specific implementations.
5. Employee Management:
Suppose you're building an employee management system. You could have a base class `Employee` and
derived classes like `Manager`, `Developer`, and `Designer`. Each employee type would have methods
like `calculateSalary()` and `displayInfo()`. With polymorphism, you could store all employee types in a
single list and iterate through them to perform actions like calculating total salary or displaying employee
information.