1. What is OOP?
Object Oriented Programming (OOP) is a programming paradigm that uses objects to design software systems.
Objects hide internal implementation details and only expose the required functionality to the user.
Example:
When riding a motorbike, we only use functions like accelerate or brake but do not know its internal mechanism.
2. Elements of OOP
Main elements of OOP are:
- Object
- Class
- Method
- Encapsulation
- Information Hiding
- Inheritance
- Polymorphism
3. Characteristics of OOP
Key characteristics of Object-Oriented Programming:
- Emphasis on data rather than procedures
- Programs divided into objects
- Data and functions are tied together
- Data hiding prevents unauthorized access
- Objects communicate through functions
- New data and functions can easily be added
- Uses bottom-up design approach
4. Basic Concepts of OOP
Important concepts used in OOP:
- Object
- Class
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
- Message Passing
- Dynamic Binding
5. What is an Object?
An object is an instance of a class.
It contains:
- State (data)
- Behavior (methods/functions)
- Identity
Example:
Car, Student, Bank Account etc.
6. What is Encapsulation?
Encapsulation is the process of binding data and functions into a single unit (class) and restricting direct access to some components.
Access Specifiers used:
- Public
- Private
- Protected
7. What is a Class?
A class is a blueprint used to create objects.
It defines:
- Data members (variables)
- Member functions (methods)
- Access permissions
Example:
class Student
{
int id;
string name;
public:
void display();
};
8. What is a Meta-Class?
A Meta-Class is a class whose instances are themselves classes.
It provides services like managing methods, instances, and inheritance relationships.
9. What is Inheritance?
Inheritance is the process where one class acquires properties and behaviors of another class.
- Parent Class → Base class
- Child Class → Derived class
Purpose:
- Code reuse
- Hierarchical relationships
10. Object-Based vs Object-Oriented Programming
| Feature | Object-Based | Object-Oriented |
| Objects | Yes | Yes |
| Inheritance | No | Yes |
| Polymorphism | No | Yes |
Example: Ada (Object-Based)
11. What is Abstraction?
Abstraction means showing only essential information and hiding unnecessary details.
Example:
When making a phone call we only dial a number, we don’t know how network routing works.
Purpose:
- Reduce complexity
- Simplify program design
12. What is a Class Diagram?
A Class Diagram is used in UML to show:
- Classes
- Attributes
- Methods
- Relationships between classes
13. Method Overriding
Method overriding occurs when a derived class provides its own implementation of a method already defined in the base class.
Conditions:
- Same function name
- Same parameters
- Same signature
14. Operator Overloading
Operator overloading allows operators such as:
+ - == > <
to behave differently depending on the data type.
Example:
Complex operator + (Complex c1, Complex c2);
15. Method Overloading
Method overloading means multiple functions with the same name but different parameters in the same class.
Example:
int sum(int a, int b);
int sum(int a, int b, int c);
16. Polymorphism
Polymorphism means “many forms”.
It allows a single interface to perform different tasks.
Types:
- Compile-time polymorphism (overloading)
- Runtime polymorphism (overriding)
17. Base Class
A base class is the class whose properties are inherited by another class.
Example:
class Animal
{
};
18. Concrete Class
A concrete class is a class from which objects can be directly created.
19. Data Members
Data members are variables declared inside a class that store object data.
Example:
class Student
{
int id;
string name;
};
20. Constructor
A constructor is a special member function used to initialize objects.
Properties:
- Same name as class
- Automatically called when object is created
- No return type
Example:
class A
{
public:
A()
{
cout<<"Constructor called";
}
};
21. Destructor
A destructor is a special function used to destroy objects and release memory.
Example:
~A()
{
cout<<"Destructor called";
}
22. Global Variable
A global variable can be accessed from any part of the program.
23. Local Variable
A local variable is declared inside a function and can only be accessed within that function.
24. Pointer
A pointer is a variable that stores the memory address of another variable.
Example:
int *ptr;
25. Null Pointer
A null pointer does not point to any valid memory location.
Example:
int *ptr = NULL;
26. Protected Keyword
The protected access specifier allows class members to be accessed:
- Inside the class
- Inside derived classes
But not outside the class.
27. Pure Virtual Function
A pure virtual function has no implementation in base class and must be overridden in derived class.
Syntax:
class A
{
public:
virtual void show() = 0;
};
28. Generic Programming
Generic programming means writing general code that works with different data types using templates.
Example:
template <class T>
T add(T a, T b)
{
return a+b;
}
29. Multiple Inheritance Problem
The Diamond Problem occurs when a class inherits from two classes that both inherit from the same base class.
This creates ambiguity.
30. Virtual Functions
Virtual functions allow runtime polymorphism.
Benefits:
- Derived class can override base class functions
- Function call resolved at runtime
- Supports dynamic binding
31. Ternary Association
Ternary association is a relationship between three classes in UML.
Example:
Person – Insurance Policy – Contract
32. Advantages of OOP
- Code reuse
- Easy maintenance
- Better program structure
- Faster development
- Improved productivity