Object-Oriented Programming (OOP) - Overview
Object-Oriented Programming (OOP) - Overview
---
1. Class
A class is a blueprint or template for creating objects. It defines attributes and behaviors
(methods) that the created objects (instances) will have.
Example:
class Car {
String color;
void drive() {
System.out.println("Driving the car");
}
}
2. Object
An object is an instance of a class. It is a real-world entity with state and behavior.
Example:
3. Encapsulation
Encapsulation is the technique of wrapping the data (variables) and code (methods) together as
a single unit. It restricts direct access to some of the object's components, which can prevent
accidental modification.
Example: Using private variables and public getters/setters.
4. Abstraction
Abstraction means hiding the complex implementation details and showing only the essential
features of an object. It helps in reducing programming complexity.
5. Inheritance
Inheritance allows a class to inherit properties and methods from another class. This promotes
code reuse.
Example:
class Vehicle {
void move() {
System.out.println("Moving...");
}
}
6. Polymorphism
Polymorphism means the ability to take many forms. It allows methods to do different things
based on the object it is acting upon, even though they share the same name.
Example: Method Overloading and Method Overriding.
---
Benefits of OOP
Modularity: Code is organized into separate objects and classes, making it easier to manage.
Reusability: Classes and objects can be reused in other programs or parts of the same
program.
---
Common OOP Languages
Java
C++
Python
C#
Ruby
---
Conclusion