Java OOP
Java OOP (Object-Oriented Programming)
Object-Oriented Programming (OOP) in Java is a programming paradigm based on objects and classes. Java is a pure OOP language, and OOP concepts make code modular, reusable, and easier to maintain.
1. Key Concepts of Java OOP
Class – Blueprint for creating objects.
Object – Instance of a class.
Encapsulation – Wrapping data (variables) and methods together.
Abstraction – Hiding complex implementation and showing only functionality.
Inheritance – One class can inherit properties and methods of another.
Polymorphism – Ability of objects to take multiple forms.
Compile-time (Method Overloading)
Run-time (Method Overriding)
2. Class and Object Example
📌 Output:
3. Encapsulation Example
📌 Output:
Encapsulation protects data by using private variables and public getter/setter methods.
4. Inheritance Example
📌 Output:
5. Polymorphism Example
a) Compile-time Polymorphism (Method Overloading)
b) Run-time Polymorphism (Method Overriding)
📌 Output:
6. Abstraction Example
Option 1: Abstract Class
Option 2: Interface
🧠 Key Takeaways
| OOP Concept | Description |
|---|---|
| Class & Object | Blueprint & instance |
| Encapsulation | Hide data, provide getter/setter |
| Inheritance | Reuse parent class properties |
| Polymorphism | Multiple forms (overloading/overriding) |
| Abstraction | Hide complexity, show functionality |
