Today in our Java class, we discussed the fundamentals of Object-Oriented Programming (OOP). Here is my detailed summary
What is OOP?
OOP stands for Object-Oriented Programming, a paradigm (idea) used in languages like:
- Java
- C++
- Python
It focuses on creating objects and classes to organize and structure the code efficiently.
Core OOPS Concepts
1. Object
- An instance of a class.
- Has state(data/properties) and behaviour (methods/functions).
- Example: A car is an object. Its state is colour, model; behaviour is drive, brake.
2. Class
- A blueprint or template to create objects.
- Example: A movie class can create different movie objects.
POP vs OOP
POP | OOP |
---|---|
Procedure Oriented Programming | Object Oriented Programming |
Focuses on functions (procedures) | Focuses on objects and classes |
Example: C | Example: Java |
3. Encapsulation
- Binding code and data together in a single unit.
- Prevents outside classes from directly accessing data.
- Example: Car – you use drive(), but don’t know the internal engine details.
4. Abstraction
- Showing only necessary details and hiding the unwanted complexity.
- Example: Car – you see steering, pedals, dashboard; internal wiring is hidden.
5. Inheritance
- One class can inherit properties and behaviours from another class.
- Promotes code reusability.
- Example: Child class inherits from Parent class (eg: Parent → Child).
6. Polymorphism
- One interface, many forms.
- The same function or method behaves differently in different situations.
- Example: Like us – at work we do different tasks, at home we do different tasks. One person, different roles.
Java Naming Rules for Classes
- Always start with a capital letter
- Name should be meaningful
- No spaces allowed
- No special characters (except
_
or$
) - Numbers can be used but not at the beginning(only in middle or end)
Top comments (0)