0% found this document useful (0 votes)
5 views16 pages

Oops

The document provides a detailed overview of Object-Oriented Programming (OOP) concepts, focusing on classes, objects, access modifiers, and variable types. It explains the structure of a class, the characteristics of objects, and the differences between static, instance, and global variables, as well as constructors and destructors. Additionally, it covers dynamic memory allocation in C, including functions like malloc(), calloc(), realloc(), and free().

Uploaded by

harshdeepg12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views16 pages

Oops

The document provides a detailed overview of Object-Oriented Programming (OOP) concepts, focusing on classes, objects, access modifiers, and variable types. It explains the structure of a class, the characteristics of objects, and the differences between static, instance, and global variables, as well as constructors and destructors. Additionally, it covers dynamic memory allocation in C, including functions like malloc(), calloc(), realloc(), and free().

Uploaded by

harshdeepg12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

2/17/25, 1:12 PM OOPs | Detailed Syllabus

What is a Class?
A class is a blueprint or template for creating objects in object-oriented programming (OOP). It defines the attributes (data
members/fields) and methods (functions/behaviors) that the objects instantiated from the class will have.
A class provides encapsulation, meaning it groups the data and functions that operate on that data together. It also promotes code
reuse and modularity.

Structure of a Class
A class typically consists of:
1. Attributes (Fields/Properties) → These are variables that store the state or characteristics of an object.
2. Methods (Functions/Procedures) → These are functions defined within the class that operate on the attributes and define the
behavior of the object.
3. Constructor → A special method used to initialize objects when they are created.
4. Access Modifiers → Keywords like public, private, and protected that control access to attributes and methods.

class example

classDiagram
class Car {

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 1/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus
+make
+model
+year
+start_engine()
}
What is an Object?
Definition:
An object is an instance of a class. It is a concrete implementation of the class blueprint, containing specific data (state) and the methods
defined by the class. Objects are the fundamental building blocks of OOP.
Characteristics of Objects:
1. State: Represented by the attributes of the class. For example, the make, model, and year attributes of the Car class represent the state
of a specific car object.
2. Behavior: Represented by methods that can operate on the object's state. For example, calling the start_engine() method modifies or
utilizes the state of the object.

Diagram:
classDiagram
class Car {
+make
+model
+year
+start_engine()
}

car1: Car
car2: Car

Access Modifier
Access Modifiers in Java (Theory)
Access modifiers in Java define the visibility and accessibility of classes, methods, and variables. They help enforce encapsulation and
security in object-oriented programming.

Types of Access Modifiers


Modifier Within Class Same Package Subclass Outside
(Different Package
Package)

private ✅ Yes ❌ No ❌ No ❌ No
default (no ✅ Yes ✅ Yes ❌ No ❌ No
keyword)

protected ✅ Yes ✅ Yes ✅ Yes ❌ No


public ✅ Yes ✅ Yes ✅ Yes ✅ Yes

1. Private Access Modifier (private)


• Members marked private are only accessible within the same class.
• They are not accessible in subclasses, other classes, or even in the same package.
• Used for data hiding, preventing external access to sensitive data.
• Commonly accessed using getter and setter methods.

2. Default (Package-Private) Access Modifier (No keyword used)


• If no access modifier is specified, it is default (package-private).
• Accessible only within the same package.
• Cannot be accessed from subclasses in a different package.

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 2/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus

• Used when a class and its members should be shared only within the package.

3. Protected Access Modifier (protected)


• Accessible within the same package and subclasses in different packages.
• Not accessible to non-subclass classes outside the package.
• Used in inheritance to allow controlled access to class members.
• Prevents unrestricted access but allows child classes to use inherited members.

4. Public Access Modifier (public)


• Accessible everywhere (inside the same class, package, subclass, and outside package).
• No restrictions, making it the least restrictive access modifier.
• Used when a class, method, or variable should be accessible globally.

Key Takeaways
✔ private → Most restrictive, used for data hiding.
✔ default → Package-private, allows access only within the same package.
✔ protected → Accessible within the same package + subclasses in different packages.
✔ public → Least restrictive, accessible everywhere.
Using proper access modifiers ensures data security, encapsulation, and better code organization. 🚀

Static vs Instance vs Global Variables


In programming, variables can be classified into static (class), instance, and global based on their scope, lifetime, and sharing behavior.
Understanding the differences helps in memory management, data encapsulation, and optimizing program efficiency.

Comparison Table
Variable Type Scope Lifetime Sharing
(Where it is accessible) (How long (Access across
it exists) objects/classes)

Static (Class Within the class (shared Exists for Shared among
Variable) among all instances) the entire all instances of
program the class
execution

Instance Within a specific object Exists as Unique to each


Variable (instance) long as the instance (Not
object shared)
exists

Global Variable Accessible from Exists for Accessible from


anywhere in the the entire all classes and
program program functions
execution

1. Static Variables (Class Variables)


• Defined at the class level and shared among all instances of the class.
• Memory is allocated only once, when the class is loaded.
• Accessible without creating an instance (using ClassName.variable).
• Changes made to a static variable affect all objects of the class.
• Useful for counters, constants, and shared resources.
Key Points:
✔ Belongs to the class, not individual objects.
✔ Initialized once and remains until the program ends.
✔ Used for shared data across all objects of a class.

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 3/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus

2. Instance Variables
• Each object (instance) gets its own copy of the variable.
• Memory is allocated when an object is created and deallocated when the object is destroyed.
• Changes made to one object’s instance variable do not affect other objects.
• Useful for storing unique attributes of an object.
Key Points:
✔ Defined inside the class but outside methods.
✔ Lifetime is until the object is garbage collected.
✔ Used for object-specific data (e.g., a person’s name, car model).

3. Global Variables
• Declared outside of all classes and functions, making them accessible throughout the program.
• Exists from the start to the end of the program.
• Can be accessed and modified from anywhere, making them less secure.
• Generally avoided in OOP due to poor encapsulation and risk of unintended modifications.
Key Points:
✔ Accessible from any class or function.
✔ Exists throughout the entire program execution.
✔ Used in small scripts but discouraged in large applications.

Key Differences & Best Practices


Aspect Static Variable Instance Global Variable
Variable

Belongs to Class (Shared) Each Object Whole Program


(Unique)

Memory Once (Class Every time an Once (Program start)


Allocation load) object is created

Access ClassName.varia objectName.vari Directly accessible


ble able

Lifetime Entire program As long as the Entire program run


run object exists

Modification Affects all Affects only the Affects all


Impact instances specific object functions/classes

Use Case Shared data Unique data Global constants (if


across instances per object needed)

Best Practices
✅ Use static variables for constants and shared resources.
✅ Use instance variables for object-specific data.
✅ Avoid global variables in large applications due to poor security and maintainability.

PYQS
1. What is the primary purpose of a class in Object-Oriented Programming? (IBPS SO 2023)
A) To store multiple values in a single variable
B) To define a blueprint for creating objects
C) To execute a block of code repeatedly
D) To allow direct access to private members

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 4/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus

✅ Correct Answer: B) To define a blueprint for creating objects


📌 Explanation: A class is a blueprint/template for creating objects. It defines attributes (data members) and methods (behaviors) that
objects instantiated from the class will have.

2. Which access modifier allows a variable to be accessed only within the same class? (IBPS SO 2022)
A) public
B) protected
C) private
D) default
✅ Correct Answer: C) private
📌 Explanation: The private access modifier restricts access to within the same class only. It is used to hide data from external access.

3. What is the key difference between a static variable and an instance variable? (IBPS SO 2023)
A) Static variables are stored per object, whereas instance variables are shared among all objects
B) Static variables are shared among all instances, while instance variables are unique to each object
C) Instance variables can be accessed without creating an object, whereas static variables require an instance
D) There is no difference; both work the same way
✅ Correct Answer: B) Static variables are shared among all instances, while instance variables are unique to each object
📌 Explanation: A static variable belongs to the class and is shared across all instances, whereas an instance variable is specific to each
individual object.

4. In Java, which access modifier allows visibility within the same package but not outside it? (IBPS SO 2021)
A) public
B) private
C) protected
D) default (no modifier)
✅ Correct Answer: D) default (no modifier)
📌 Explanation: If no access modifier is specified, the default (package-private) modifier is applied, making the member accessible only
within the same package but not outside it.

5. What is the key disadvantage of using global variables in Object-Oriented Programming? (IBPS SO 2021)
A) They take up more memory
B) They cannot be modified once declared
C) They violate encapsulation and can lead to unintended modifications
D) They make code more efficient
✅ Correct Answer: C) They violate encapsulation and can lead to unintended modifications
📌 Explanation: Global variables can be accessed from anywhere in the program, making them prone to unintended changes and
violating data encapsulation, which is a core OOP principle.

Constructor vs Destructor in Object-Oriented Programming


Constructor and Destructor Overview
• Constructor: A special method that is automatically called when an object is created. It initializes the object.
• Destructor: A special method that is automatically called when an object is destroyed. It is used for cleanup tasks like releasing
memory.

Comparison Table: Constructor vs Destructor


Aspect Constructor Destructor

Purpose Initializes an object when it is created Cleans up resources when an object


is destroyed

Call Mechanism Automatically called when an object is Automatically called when an object
instantiated goes out of scope or is manually
deleted

Parameters Can have parameters (except for Cannot have parameters


default constructors)

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 5/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus

Overloading Can be overloaded (multiple Cannot be overloaded (only one


constructors in a class) destructor per class)

Return Type No return type (not even void) No return type

Memory Allocates or initializes resources Frees memory and other allocated


Management resources

Declaration Uses the same name as the class Uses a tilde (~) before the class
name

Access Can be public, private, or protected Usually public but rarely defined
Modifiers explicitly

Explicit Call Can be called explicitly (though not Cannot be called explicitly, only
common) invoked by the system

Use Case Used for setting default values, Used for releasing memory, closing
memory allocation, and object setup file handles, or cleaning up resources

Types of Constructors
1. Default Constructor (No-Argument Constructor)
• A constructor that takes no parameters and initializes objects with default values.
• If no constructor is defined, the compiler provides a default constructor.
2. Parameterized Constructor
• A constructor that takes arguments to initialize an object with specific values.
• Allows different objects to have different initial values.
3. Copy Constructor
• A constructor that creates a new object by copying an existing object.
• Used in object cloning.
4. Static Constructor (C# only)
• Used to initialize static members of a class.
• Runs only once when the class is loaded into memory.
5. Private Constructor
• Used to restrict object creation outside the class.
• Useful in singleton design patterns.

Key Takeaways
✔ Constructors initialize objects, while destructors clean up resources.
✔ Constructors can be overloaded, but destructors cannot.
✔ Destructors are automatically invoked when an object is destroyed.
✔ Different types of constructors allow flexibility in object initialization.

Dynamic Memory Allocation in C:


Dynamic memory allocation functions allow programs to allocate memory at runtime instead of compile time. The key functions in C for
dynamic memory management are:

1. malloc() (Memory Allocation)


Definition:
malloc() allocates a single block of memory of a given size and returns a pointer to the allocated memory. The memory is not initialized
(contains garbage values).
Syntax:
void* malloc(size_t size);
• size_t size → Number of bytes to allocate.

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 6/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus

• Returns a void pointer (void*), which needs to be typecast into the required type (int*, float*, etc.).
• If allocation fails, it returns NULL.
Key Features:
✔ Allocates uninitialized memory.
✔ Returns a void pointer that must be typecast.
✔ If memory allocation fails, it returns NULL.

2. calloc() (Contiguous Allocation)


Definition:
calloc() allocates multiple blocks of memory, initializes them to zero, and returns a pointer to the allocated memory.
Syntax:
void* calloc(size_t num, size_t size);

• num → Number of elements.


• size → Size of each element in bytes.
• Returns a void pointer, which needs to be typecast into the required type.
• If allocation fails, it returns NULL.
Key Features:
✔ Allocates multiple memory blocks.
✔ Initializes allocated memory to zero.
✔ Useful for arrays and structured data.
✔ Slower than malloc() due to initialization overhead.

3. realloc() (Reallocation)
Definition:
realloc() is used to resize previously allocated memory without losing existing data.
Syntax:
void* realloc(void* ptr, size_t new_size);

• ptr → Pointer to previously allocated memory (from malloc() or calloc()).


• new_size → New size of memory in bytes.
Key Features:
✔ Increases or decreases memory size dynamically.
✔ Retains existing data (if memory is expanded).
✔ If reallocation fails, it returns NULL (original memory remains unchanged).
✔ If ptr = NULL, it behaves like malloc().

4. free() (Memory Deallocation)


Definition:
free() releases dynamically allocated memory back to the system.
Syntax:
void free(void* ptr);
• ptr → Pointer to allocated memory.
• After free(), ptr becomes a dangling pointer (should be set to NULL).
Key Features:
✔ Frees memory to avoid memory leaks.
✔ Should always be used after dynamic allocation.
✔ Does not change the pointer, so manually set ptr = NULL.

Comparison Table: malloc() vs calloc() vs realloc() vs free()


Function Purpose Memory Parameters Returns
Initialization

malloc() Allocates single Uninitialized size (bytes) Pointer to


block (Garbage allocated

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 7/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus

values) memory (void*)


or NULL if failed

calloc() Allocates Zero-initialized num (elements), Pointer to


multiple blocks size (bytes per allocated
element) memory (void*)
or NULL if failed

realloc() Resizes existing Retains old ptr (previous Pointer to new


memory values (new allocation), memory (void*)
memory new_size (bytes) or NULL if failed
uninitialized)

free() Deallocates N/A ptr (allocated Nothing (frees


memory memory) memory)

Dynamic Memory Allocation in C++


Operator Purpose

new Allocate memory

delete Deallocate memory

new[] Allocate array memory

delete[] Deallocate array memory

Object-Oriented Programming (OOP) Concepts in Detail


1. Abstraction
Definition:
Definition:
Abstraction simplifies complex systems by focusing on essential features and hiding unnecessary details. It allows programmers to interact with
objects through simple interfaces, focusing on what they do rather than how they work internally.

Types of Abstraction
1. Data Abstraction:
2. Hides how data is stored and manipulated. It focuses on what the data represents rather than its internal structure.
• Example: A BankAccount class hides how the balance is stored and only exposes methods like deposit or withdraw.
3. Control Abstraction:
4. Hides the implementation details of operations. It focuses on what the operation does, without revealing the internal logic.
• Example: A method like deposit() hides how the transaction is processed and simply provides a way to interact with the
account.
Example:
Consider a
Car class that provides methods like start(), drive(), and stop() without showing how the engine works.
Diagram:
classDiagram
class Car {
+start()
+drive()
+stop()
}

2. Encapsulation in OOP
Definition:
• Encapsulation is the concept of bundling the data (attributes) and the methods (functions) that operate on the data into a single unit,
called a class. It restricts direct access to some of an object's components and only exposes necessary parts through public methods.

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 8/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus

This helps in protecting the object's state from unauthorized access and modification.
• Importance of Encapsulation:
1. Protects Object Integrity:
2. It ensures that an object's data is protected and can only be accessed or modified in controlled ways through methods (getters and
setters).
3. Prevents External Interference:
4. Encapsulation hides implementation details, preventing accidental or harmful changes from outside the object.
5. Facilitates Code Maintenance:
6. Changes to the internal workings of an object can be made without affecting other parts of the program, making the code easier to
maintain.
• Key Concepts:
• Private Attributes: Internal data is hidden using access modifiers (like private) to prevent external manipulation.
• Public Methods: Provide controlled access to the data (e.g., getBalance(), setBalance()).
• Data Hiding: Internal details are hidden, exposing only what is necessary for interaction.
• Encapsulation improves security, simplifies code, and enhances maintainability by ensuring controlled access to an object's data.

Example of Encapsulation in a Business Context
Consider a company with various divisions: Sales, Finance, and Accounts.
1. Finance Division: Manages all financial transactions and maintains financial records.
2. Sales Division: Handles all sales-related tasks and keeps track of each sale.
Now, if a finance officer needs sales information for a specific month, they cannot directly access the sales data. Instead, they must interact with
the Sales Division, which encapsulates the sales information and restricts access from other divisions.
This encapsulation ensures that:
• Only authorized personnel can access and modify the data.
• Each division operates independently while still being able to share necessary information through appropriate channels.

Concept Focus Purpose

Data Abstraction Interface Simplify complex systems

Encapsulation Implementation Protect data and behavior

3. Inheritance
Definition:
Inheritance is a mechanism where one class inherits properties and methods from another class. It promotes code reusability.
Types:

Example:
A Dog class inherits from an Animal class.
Diagram:
classDiagram
class Animal {
+eat()
}
class Dog {
+bark()
}
Animal <|-- Dog
4. Polymorphism
Definition:
Polymorphism is the ability of different classes to be treated as instances of the same class through a common interface. It allows one interface
to be used for a general class of actions.
If one task is performed in different ways, it is known as polymorphism. For example: to convince the customer differently, to draw something,
for example, shape, triangle, rectangle, etc.

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 9/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus

Types:
• Compile-time Polymorphism (Method Overloading): The method is related to the same name with different signatures.
• Runtime Polymorphism (Method Overriding): A method in a derived class overrides a method in the base class.
Example:
A method
draw() implemented in both Circle and Square classes.
Diagram:
classDiagram
class Shape {
+draw()
}
class Circle {
+draw()
}
class Square {
+draw()
}
Shape <|-- Circle
Shape <|-- Square

PYQS
1. What is the primary goal of Abstraction in Object-Oriented Programming?
(SBI SO)
a) To simplify complex systems by hiding unnecessary details
b) To increase the security of the system
c) To create reusable code
d) To decrease the runtime of the application
Answer: a) To simplify complex systems by hiding unnecessary details
Explanation: Abstraction simplifies complex systems by focusing on what the object does rather than how it works internally.

2. Which of the following is an example of Data Abstraction?


a) The deposit() method in a BankAccount class
b) A BankAccount class exposing its internal balance directly
c) The withdraw() method in a BankAccount class
d) A method to set the balance in a BankAccount class
Answer: a) The deposit() method in a BankAccount class
Explanation: Data Abstraction hides internal data representation, focusing on what the data represents through high-level methods.

3. Which concept allows access control in OOP by hiding internal details of an object?
(SBI SO)
a) Inheritance
b) Polymorphism
c) Encapsulation
d) Abstraction
Answer: c) Encapsulation
Explanation: Encapsulation involves wrapping the data and methods into a single unit and restricting access to internal details via access
modifiers.

4. Which of the following is an advantage of encapsulation in software development?


(IBPS SO)
a) Easier collaboration between teams
b) Direct access to data attributes
c) Protecting object data from unauthorized access
d) Increased memory usage
Answer: c) Protecting object data from unauthorized access
Explanation: Encapsulation restricts direct access to an object's data, making it more secure and less prone to accidental manipulation.

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 10/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus

5. What type of inheritance allows one class to inherit properties from multiple classes?
(SBI SO)
a) Single Inheritance
b) Multiple Inheritance
c) Multi-level Inheritance
d) Hierarchical Inheritance
Answer: b) Multiple Inheritance
Explanation: Multiple Inheritance allows a class to inherit properties from more than one base class, although it’s restricted in some languages
like Java (can be achieved using interfaces).

6. In which OOP concept is a subclass able to reuse methods and properties of a superclass?
(IBPS SO)
a) Abstraction
b) Polymorphism
c) Inheritance
d) Encapsulation
Answer: c) Inheritance
Explanation: Inheritance allows a subclass to inherit properties and methods from a superclass, promoting code reuse.

7. Which of the following is an example of Encapsulation in a banking system?


(SBI SO)
a) The BankAccount class allows users to directly set the balance.
b) The BankAccount class hides the balance and only allows modification via deposit and withdrawal methods.
c) A bank provides direct access to transaction history.
d) Bank managers can modify account information without restrictions.
Answer: b) The BankAccount class hides the balance and only allows modification via deposit and withdrawal methods.
Explanation: Encapsulation ensures that the balance is hidden and can only be modified via controlled methods like deposit() and withdraw().

8. Which concept hides unnecessary details from the user while exposing only essential features?
(IBPS SO 2024)
a) Abstraction
b) Encapsulation
c) Inheritance
d) Polymorphism
Answer: a) Abstraction
Explanation: Abstraction hides the complexities of a system, allowing users to interact with it at a high level, focusing only on essential
functions.

9. What type of OOP relationship is illustrated when a Car class inherits properties like speed and fuel from a Vehicle class?
a) Inheritance
b) Abstraction
c) Encapsulation
d) Polymorphism
Answer: a) Inheritance
Explanation: Inheritance allows a Car class to inherit common properties and methods from a Vehicle class, promoting code reuse.

10. Which OOP principle allows a class to be reused by inheriting methods and attributes from another class without modifying the
original class?
(IBPS SO)
a) Encapsulation
b) Inheritance
c) Abstraction
d) Polymorphism
Answer: b) Inheritance
Explanation: Inheritance allows one class (child) to inherit properties and methods from another class (parent), enabling code reuse without
modifying the original class.

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 11/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus

5. Message Passing
Definition:
Message passing is how objects communicate with each other. It involves sending and receiving messages to invoke the behavior of another
object.
Example:
In a chat application, a
User class can send messages to another User.
Diagram:
classDiagram
class User {
+sendMessage(message)
+receiveMessage()
}
class ChatApp {
+startChat(user1, user2)
}
6. Coupling
Definition:
Coupling refers to the degree of direct knowledge a class has about another class. Lower coupling is preferred as it enhances modularity.
Types:
• Tight Coupling: Classes are highly dependent on one another.
• Loose Coupling: Classes are independent and communicate through interfaces.
Example:
Using interfaces and abstract classes to achieve loose coupling.
7. Cohesion
Definition:
Cohesion refers to how closely related and focused the responsibilities of a single class are. High cohesion is desirable, as it makes the class
easier to understand and maintain.
Types:
High Cohesion
Definition: High cohesion occurs when the components of a module or class are closely related and focused on a single responsibility, making
the system easier to maintain, understand, and reuse.
Diagram:
+-------------------+
| Order Class |
|-------------------|
| + placeOrder() |
| + cancelOrder() |
| + checkStatus() |
+-------------------+
|
v
+-------------------+
| Order Details |
|-------------------|
| - orderID |
| - orderDate |
| - customerDetails |
+-------------------+
Low Cohesion
Definition: Low cohesion occurs when the components of a module or class are unrelated and perform multiple, distinct tasks, leading to a
complex and hard-to-maintain system.
Diagram:
+---------------------+

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 12/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus
| UserManager |
|---------------------|
| + createUser() |
| + logActivity() |
| + sessionTimeout() |
| + sendEmail() |
+---------------------+
• High Cohesion: Focused on one responsibility, leading to better readability and maintenance.
• Low Cohesion: Performs unrelated tasks, resulting in complexity and decreased maintainability.
8. Association
Definition:
Association defines a relationship between two classes. It represents how two objects interact.
Types:
• One-to-One: One object of class A is associated with one object of class B.
• One-to-Many: One object of class A is associated with multiple objects of class B.
• Many-to-Many: Multiple objects of one class are associated with multiple objects of another class.
Example:
A
Teacher class associated with a School class.
Diagram:
classDiagram
class Teacher {
+teach()
}
class School {
+admitStudent()
}
Teacher --> School
9. Aggregation
Definition:
Aggregation is a special form of association that represents a "whole-part" relationship, where parts can exist independently of the whole.
Example:
A
Library class that contains Books, which can be borrowed or exist independently.
Diagram:
classDiagram
class Library {
+addBook(book)
}
class Book {
+read()
}
Library o-- Book
10. Composition
Definition:
Composition is a stronger form of aggregation. It implies ownership and a "part-of" relationship, where the lifecycle of the part is tied to the
lifecycle of the whole.
Example:
A
House class composed of Rooms, which cannot exist without the house.
Diagram:
classDiagram
class House {
+addRoom(room)

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 13/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus
}
class Room {
+decorate()
}
House *-- Room
11. Method Overloading
Definition:
Method overloading allows a class to have multiple methods with the same name but different parameters. It supports compile-time
polymorphism.
Example:
A class
MathOperations with overloaded methods for add.
Diagram:
classDiagram
class MathOperations {
+add(int a, int b)
+add(double a, double b)
+add(int a, int b, int c)
}
12. Method Overriding
Definition:
Method overriding allows a subclass to provide a specific implementation of a method that is already defined in its superclass.
Example:
A base class
Animal has a method makeSound(), and a derived class Dog overrides it.
Diagram:
classDiagram
class Animal {
+makeSound()
}
class Dog {
+makeSound()
}
Animal <|-- Dog
13. Exceptions
Definition:
Exceptions are anomalies that occur during the execution of a program. Exception handling is a mechanism to respond to exceptions and
ensure the program continues running or gracefully terminates.
Example:
Catching and handling an
ArithmeticException in case of division by zero.
Diagram:
classDiagram
class Exception {
+catch()
+throw()
}
OOP Multiple-Choice Questions
1. What is a class in OOP?
• A) A blueprint for creating objects
• B) A specific object created from a class
• C) A collection of functions
• D) A data type that represents a single value
2. Which of the following is NOT a principle of OOP?

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 14/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus

• A) Encapsulation
• B) Inheritance
• C) Polymorphism
• D) Compilation
3. What is inheritance in OOP?
• A) A mechanism where one class acquires properties from another
• B) An object's ability to take on multiple forms
• C) Protecting the internal state of an object
• D) A way to organize code into different categories
4. Which of these is an example of polymorphism?
• A) A single function with multiple implementations
• B) A class with multiple constructors
• C) A variable that can hold different data types
• D) An object that interacts with another object
5. What does encapsulation achieve?
• A) Better performance
• B) Protection of object state
• C) Increased complexity
• D) Direct access to data
6. What is a constructor in OOP?
• A) A method that performs calculations
• B) A special method for initializing objects
• C) A type of destructor
• D) A global function
7. What does data abstraction do?
• A) Hides the complexity of the implementation details
• B) Exposes all details of data
• C) Combines multiple classes
• D) None of the above
8. Which of the following allows a function to operate on different types of data?
• A) Overloading
• B) Inheritance
• C) Encapsulation
• D) Data hiding
9. What is method overloading?
• A) Defining multiple methods with the same name but different parameters
• B) Creating a method that calls itself
• C) Defining a method in a subclass that has the same name as its superclass
• D) None of the above
10. Which keyword is used to inherit a class in most OOP languages?
• A) implements
• B) extends
• C) inherits
• D) uses
Answers
1. A) A blueprint for creating objects
2. D) Compilation
3. A) A mechanism where one class acquires properties from another
4. A) A single function with multiple implementations
5. B) Protection of object state
6. B) A special method for initializing objects
https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 15/16
2/17/25, 1:12 PM OOPs | Detailed Syllabus

7. A) Hides the complexity of the implementation details


8. A) Overloading
9. A) Defining multiple methods with the same name but different parameters
10. B) extends

Variable Type Scope Lifetime Sharing

Static (Class) Class-level Program Shared among


lifetime instances

Instance Instance-level Instance lifetime Unique to each


instance

Global Program-level Program Accessible from


lifetime anywhere

https://app.clickup.com/9016631242/v/dc/8cpxqya-896/8cpxqya-836 16/16

You might also like