Chapter 2 CS (Class 12)
Chapter 2 CS (Class 12)
Q. What is a class?
2
Q. What are characteristics of procedural programming?
Ans.: The characteristics of procedural programming are:
Its emphasis on writing algorithm (step by step procedures)
rather than data.
Large programs are divided into smaller programs called
functions.
Functions communicate with global variables.
Data can more freely from one function to another function.
It follows top-down programming approach.
Example- C, FORTRANM, COBOL etc.
Q. What are the Characteristics of object-oriented programming?
Ans.: The characteristics of object-oriented programming are:
Its emphasis on data rather than procedures.
Programs are divided into small parts known as objects.
Objects can move and communicate with each other through
member functions.
Data hiding is possible due to abstraction.
It follows bottom-up approach.
Examples- C++, JAVA, Python, C#, NET etc.
BASIC CONCEPTS OOP
Object-oriented programming (OOP) helps overcome the
limitations or problems faced by conventional or traditional
programming approach like procedural programming Traditional
methods often suffer from issues such as code redundancy
(repeating code) and difficult maintenance, especially in large or
complex programs.
OPP address these issues by introducing a set of case concepts
(also called pillar) that make programs more modular, reusable, and
easier to manage.
These concepts are:
Data Abstraction.
Data Encapsulation
Modularity
Inheritance
Polymorphism
Q. What is data abstraction?
3
Ans.: Data Abstraction is the process of hiding unnecessary details
and showing only the essential features of an object or systems by
allowing users to focus only on what they meet to know.
For example:
When driving a car, the diver only needs to know how to use
the steering wheel, clutch, accelerator and breaks. The internal
working of the engine wiring or fuel injection system is hidden from
the driver because it’s not necessary to operate the car. This is
abstraction.
Q. What is Data Encapsulation?
Ans.: Data Encapsulation is the process of wrapping data (variables)
and functions (methods) together into a single unit called class. It is
one of the key features of object-oriented programming and
supports the concept of data hiding.
For example:
Just like important documents are kept in a locked box and can
only be accessed using a key, Class variables are kept private and
can only be accessed using specific methods.
Q. What is Modularity?
Ans.: Modularity is the process of dividing a program into smaller,
independent parts called modules. Each module performs a specific
task, and all modules work together to form a complete program.
This makes the program easier to understand manage, debug and
update since changes can be made to one module without affecting
the others.
For example:
Just like our body is made up of parts like the hands, legs, and
brain – each with a specific function (movement, working, and
thinking) – a program is made of different modules that handle
different tasks.
Q. What are the advantages of Modularity?
Ans.: Dividing a program into modules has the following advantages:
It reduces code complexity, making it easier to write and
manage large programs.
It allows for well-defined, independent sections, which can be
tested, debugged, and updated separately.
4
Note:
Bag= an error in the code. (Wrong output, system crash, unexpected
behavior)
Debug= the process of locating that bug and correcting or fixing it.
Q. What is Inheritance?
Ans.: Inheritance is an object-oriented programming concept where
one class can inherit properties and behavior (data and methods)
from another class. It allows code reusability and helps create a
hierarchy between classes.
For example:
A class car can inherit properties from a class automobile,
which itself inherits from another class vehicle. Here, vehicle is the
base (or parent) class, and automobile, and car are derived (or child)
classes that inherits from it.
Q. What are the features or characteristics of inheritance?
Ans.: Inheritance provides the following features:
1. It helps us model real-world relationships in programs by
allowing one class to inherit from another.
2. It supports code reusability; a new class can be created by
building on existing ones.
3. It is transitive in nature- if class A inherits from class B, and
class C inherits from class A, then class C automatically inherits
the properties of both A and B.
Q. What is polymorphism?
Ans.: polymorphism means “many form”. It is a feature of object-
Oriented programming that allows the same function or method
name to behave differently depending on the objects or context.
For example:
One common example of polymorphism is function overloading,
where multiple functions have the same name but different
parameters.