Chapter 5: Object-Oriented Programming – Class 12 Computer Science Notes
Importantedunotes.com
Back to Computer Notes

Core Concepts of OOP

Q1. What is OOP? Write down the features of OOP.

The relatively newer concept of developing a computer program with an approach to designing a reusable program is called OOP.

The features of OOP are as follows:

a) Object
b) Class
c) Encapsulation
d) Data Abstraction
e) Inheritance
f) Polymorphism

Object

Everything around ourselves is an object in OOP. An object is the basic runtime entity in OOP which consists of data and functions. It stores data in variables.

Class

Generally, a class is a category/group which is used to identify some people or things in this world. A class provides the structure of an object and defines the prototype of the object.

Data Abstraction

It is data hiding. We can show only necessary information and can hide the unnecessary part. Abstraction is one of the key concepts of OOP languages.

Encapsulation

The wrapping of related data and functions (that operate on data) into a single unit (called a class) is known as encapsulation.

Polymorphism

The term polymorphism is formed by the combination of two Greek words: ‘poly’ (means many) and ‘morph’ (means form), i.e., the ability to take more than one form.


Q2. What is OOP? Explain the advantages and disadvantages of OOP.

The relatively newer concept of developing a computer program with an approach to designing and reusable programs is known as OOP.

Advantages

Improved software development productivity: Objects can be extended to include new attributes and behaviors. Objects can also be reused within and across applications by using modularity, extensibility, and reusability, so OOP provides improved software development.
Improved software maintainability: It has three factors: modularity, extensibility, and reusability, so OOP software is easier to maintain.
Faster development: Reuse enables faster development.
Lower cost of development: The reuse of software also lowers the cost of development.

Disadvantages

Large programming size: OOP typically involves more lines of code than procedural programs.
Slower programs: OOP programs are typically slower than procedural-based programming as they typically require more instructions to be executed.

Q3. Write down the Applications of OOP. 2 Marks

The applications of OOP are as follows:

Real-time systems
Simulation and modeling
Hypertext and Hypermedia
Decision support systems
Client-server systems
Object-oriented Expert Systems

Q4. Define inheritance. Explain about different types of inheritance.

The process by which objects of one class acquire the similar properties of objects of another class from which they are derived is called inheritance.

Types of inheritance:

Single inheritance
Multiple inheritance
Multilevel inheritance
Hybrid inheritance
Hierarchical inheritance

1. Single inheritance

In single inheritance, a class derives from one base class only. This means that there is only one subclass that is derived from one superclass.

2. Multiple inheritance

Multiple inheritance is a type of inheritance in which a class derives from more than one class. (Class C is a subclass that has Class A and Class B as its parents).

3. Multilevel inheritance

A derived class that is created from another derived class is called multi-level inheritance. This inheritance can have many levels as long as our implementation doesn’t go wayward.

4. Hybrid Inheritance

Hybrid inheritance is usually a combination of more than one type of inheritance (single, hierarchical, and multi-level).

5. Hierarchical inheritance

In hierarchical inheritance, more than one class inherits from a single base class. This gives it a structure of a hierarchy.


Q5. Write the difference between Object-Oriented Programming and POP/Structured Programming.
S.N.Structured Programming / POPObject-Oriented Programming (OOP)
1Structured programming is designed focusing on process/logical structure and then the data required for that process.Object-oriented programming is designed focusing on data.
2Structured programming follows a top-down approach.Object-oriented programming follows a bottom-up approach.
3Structured programming is less secure as there is no way of data hiding.Object-oriented programming is more secure as it has a data hiding feature.
4Structured programming cannot solve complex programs easily.Object-oriented programming can solve any complex programs.
5Structured programming provides less reusability and more function dependency.Object-oriented programming provides more reusability and less function dependency.
6Less abstraction and less flexibility.More abstraction and more flexibility.

Old is Gold: Multiple Choice Questions

Select an option to view the correct answer and justification.

1. Which OOP feature allows a class to inherit properties and behavior from another class?
a) Inheritance
b) Encapsulation
c) Abstraction
d) Polymorphism
Correct Answer: a) Inheritance
Justification: Inheritance is the OOP feature that allows a class (child) to acquire the properties and behaviors of another class (parent).
2. Which concept allows you to reuse the written code in OOPs?
a) Encapsulation
b) Inheritance
c) Class
d) Polymorphism
Correct Answer: b) Inheritance
Justification: Inheritance enables a new class to reuse the attributes and methods of an existing class, avoiding duplicate code.
3. Which of the following concepts in object-oriented programming refers to binding data and functions into a single unit?
a) Encapsulation
b) Abstraction
c) Polymorphism
d) Inheritance
Correct Answer: a) Encapsulation
Justification: Encapsulation is the wrapping of related data and functions that operate on that data into a single unit called a class.
4. Which of the following is not an OOPs concept?
a) Class
b) Exception
c) Encapsulation
d) Polymorphism
Correct Answer: b) Exception
Justification: Exception handling is an error-handling mechanism, not one of the core OOP concepts (which include class, encapsulation, and polymorphism).
5. What is it called in a class to wrap/hide data into a single unit?
a) Abstraction
b) Polymorphism
c) Encapsulation
d) Inheritance
Correct Answer: c) Encapsulation
Justification: Encapsulation refers to wrapping data and its related functions together into a single unit, and often hiding the internal details.
6. Which feature of OOP illustrates code reusability?
a) Polymorphism
b) Abstraction
c) Inheritance
d) Encapsulation
Correct Answer: c) Inheritance
Justification: Inheritance lets a new class reuse the code of an existing class instead of rewriting it, making it the feature most directly tied to reusability.
7. OOP stands for:
a) Operator overloading programming
b) Object-oriented programming
c) Object overloading programming
d) None of the above
Correct Answer: b) Object-oriented programming
Justification: OOP is the standard abbreviation for Object-Oriented Programming, a paradigm based on objects and classes.
8. ___ is a concept of things with defined boundaries that are relevant to the problem we are dealing with.
a) Object
b) Variable
c) Class
d) None of the above
Correct Answer: a) Object
Justification: An object represents a well-defined “thing” with clear boundaries and relevance to the problem being modeled, holding data and functions.
9. ___ is a collection or group of similar objects that have the same properties, common behavior, and relationships.
a) Object
b) Constant
c) Class
d) None of the above
Correct Answer: c) Class
Justification: A class is a blueprint or category that groups similar objects sharing common properties, behavior, and relationships.
10. ___ is a property that allows the reuse of an existing class to build a new class.
a) Class
b) Inheritance
c) Encapsulation
d) Polymorphism
Correct Answer: b) Inheritance
Justification: Inheritance is precisely the property that lets a new class be built on top of an existing class, reusing its members.

Short Answer Questions

1. Write a short note on class and object in OOPs with a real-world example.

Object

Everything around ourselves is an object in OOP. An object is the basic runtime entity in OOP which consists of data and functions. It may represent a person, place, bank account, table of data, or any item that the program has to handle. It stores data in variables. Every object has two things: properties and behavior.

Example: Object – Student

Data: Roll no, Name, Grade
Function: Study(), Sleep(), Play_game(), Calculate()

Class

Generally, a class is a category/group which is used to identify some people or things in this world. A class provides the structure of an object and defines the prototype of the object. Every class has three important things: name, attributes/features, and operations/functions.

Example:

item.cpp
class Item {
private:
    int code;
    float price;
public:
    void get_data();
    void display_data();
};

2. Describe the inheritance concept with an example.

Inheritance is a key concept in OOP that allows one class (called the child or subclass) to acquire the properties and behaviors (attributes and methods) of another class (called the parent or superclass). This promotes code reusability and a hierarchical class structure.

Example: Consider a parent class “Vehicle” and child classes like “Car” and “Bike”.


3. What is OOP? List the characteristics of OOP.

The characteristics of OOP are as follows:

Encapsulation: Bundles data (attributes) and methods (functions) together in a class, and restricts access to the data using access modifiers (private, public, etc.).
Inheritance: Allows a class (child class) to inherit properties and behaviors (methods) from another class (parent class).
Modularity: Breaks down the programming into smaller, manageable chunks (objects) which can be developed and tested independently.
Message Passing: Objects communicate with each other by sending and receiving messages (method calls) to perform tasks.
Class and Object: Class defines the structure (blueprints), while objects are instances of that class holding real data.

4. Explain the terms polymorphism and inheritance.

Polymorphism

Polymorphism is a concept in object-oriented programming that allows objects of different classes to be treated as objects of a common superclass. It means “many forms” and it enables one interface to be used for different data types. There are two types of polymorphism:

Compile-time polymorphism
Run-time polymorphism

Inheritance

Inheritance is a mechanism in OOP where one class (subclass or child class) acquires the attributes and methods of another class (superclass or parent class). This allows for code reuse and establishes a relationship between different classes. The subclass can add its own unique methods and properties in addition to the inherited ones. There are two main types of inheritance:

Single inheritance
Multilevel inheritance

5. What is procedural-oriented programming? Explain.

Procedural-oriented programming (POP) is a programming paradigm that follows a step-by-step approach to solve problems, where the program is divided into small, manageable procedures or functions. Each function performs a specific task and those functions are executed sequentially to achieve the desired outcome. POP focuses on procedures or routines that operate on data and control the flow of execution. In POP, the primary focus is on the sequence of actions that need to be performed to achieve a result.


6. What is object-oriented programming? How is it different from procedural-oriented programming?

Object-oriented programming (OOP) is a paradigm that organizes software design around objects, which are instances of classes that encapsulate both data and behavior (methods). It emphasizes encapsulation, inheritance, polymorphism, and abstraction to create modular, reusable, and maintainable codes.

In contrast, procedural-oriented programming (POP) focuses on functions or procedures that operate on global data, with a linear flow of execution. The main difference is that OOP structures code around objects and their interactions, whereas POP organizes codes around functions and a sequence of steps leading to operate. OOP provides more flexibility, scalability, and reusability compared to POP.


7. Name tools that are used in program design. Polymorphism and inheritance are important concepts of OOP. What do you understand by these two terms?

Tools used in program design:

Flowcharts: Visualize the logic and flow of a program.
Pseudocode: A simple, readable description of an algorithm without strict syntax.
Data Flow Diagrams: Visualize how data flows within a system.
Entity-relationship Diagrams: Represent the relationship between data entities in a database.
Note: Polymorphism and inheritance are defined in Question 4 above.

8. Explain about different types of inheritance.

In OOP, inheritance is a mechanism to share code and behavior. It allows a programmer to derive the behavior of a class in the definition of new classes. It is the process by which objects of one class acquire similar properties of objects of another class from which they are derived, providing the ability to use an existing class to create a new one. It is a relationship between two or more classes.

Types of Inheritance:

Single inheritance
Multiple inheritance
Multilevel inheritance
Hybrid inheritance
Hierarchical inheritance

1. Single Inheritance

In single inheritance, a class derives from one base class only. This means that there is only one subclass that is derived from one superclass.

Single Inheritance Diagram Object-Oriented Programming

Fig: Single Inheritance

2. Multiple Inheritance

Multiple inheritance is a type of inheritance in which a class derives from more than one class.

Multiple Inheritance Diagram Object-Oriented Programming

Fig: Multiple Inheritance

3. Multilevel Inheritance

A derived class that is created from another derived class is called multilevel inheritance. This inheritance can have as many levels as long as our implementation doesn’t go wayward.

Multilevel Inheritance Diagram Object-Oriented Programming

Fig: Multilevel Inheritance

4. Hybrid Inheritance

Hybrid inheritance is usually a combination of more than one type of inheritance (single, hierarchical, and multi-level).

Hybrid Inheritance Diagram Object-Oriented Programming

Fig: Hybrid Inheritance

5. Hierarchical Inheritance

In hierarchical inheritance, more than one class inherits from a single base class as shown in the representation below. This gives it a structure of a hierarchy.

Hierarchical Inheritance Diagram

Fig: Hierarchical Inheritance

ЁЯУД View / Download Full PDF Notes

If the PDF doesn’t load, click here to open it in Google Drive.

ЁЯУЪ Also Read: NEB Notes

Scroll to Top