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

Java Oop Notes (Clean & Structured)

Java Object Oriented Programming (OOP) is a programming style that represents real-life entities in code, with Java being a nearly pure OOP language. The four pillars of OOP are Class & Object, Encapsulation, Inheritance, and Polymorphism, each serving distinct purposes such as data protection and feature sharing. Understanding OOP is crucial for code reusability, maintenance, and real-life modeling, making it essential for interviews and exams.

Uploaded by

baldwinam116
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 views5 pages

Java Oop Notes (Clean & Structured)

Java Object Oriented Programming (OOP) is a programming style that represents real-life entities in code, with Java being a nearly pure OOP language. The four pillars of OOP are Class & Object, Encapsulation, Inheritance, and Polymorphism, each serving distinct purposes such as data protection and feature sharing. Understanding OOP is crucial for code reusability, maintenance, and real-life modeling, making it essential for interviews and exams.

Uploaded by

baldwinam116
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

🌟 Java Object Oriented Programming (OOP)

OOP kya hota hai? 🤔


OOP ek programming style hai jisme hum real life cheezon ko code ke form mein represent karte hain.

Examples: - Car 🚗 - Student 👨🎓 - Mobile 📱

Java almost pure OOP based language hai.

🔑 OOP ke 4 Pillars (Yaad rakhne layak)


1️⃣ Class & Object
2️⃣ Encapsulation 🔐
3️⃣ Inheritance 👨‍👦
4️⃣ Polymorphism 🔄

Ab ek ek karke samajhte hain.

1️⃣ Class & Object 🧱

📦 Class kya hoti hai?

Class ek blueprint / design hoti hai.

Example: - Car ka design = Class


- Asli car = Object

class Student {
String name;
int age;
}

Yahaan: - Student → class


- name , age → data members

🎯 Object kya hota hai?

Object class ka real instance hota hai.

class Student {
String name;

1
int age;

void display() {
[Link](name);
[Link](age);
}

public static void main(String[] args) {


Student s1 = new Student(); // object creation
[Link] = "Rahul";
[Link] = 20;
[Link]();
}
}

🧠 Samajhne wali baat:


new Student() → memory mein object banta hai

2️⃣ Encapsulation 🔐 (Data Protection)


Encapsulation ka matlab:
Data + Methods ko ek jagah band karna aur direct access se bachana

Use hota hai: - private - Getter & Setter

class BankAccount {
private int balance = 5000;

public int getBalance() {


return balance;
}

public void setBalance(int amt) {


balance = amt;
}
}

✅ Fayde: - Data secure rehta hai 🔒


- Control milta hai ki data kaise use ho

3️⃣ Inheritance 👨‍👦 (Parent → Child)


Inheritance ka matlab:
Ek class doosri class ke features use kare

2
class Animal {
void eat() {
[Link]("Eating...");
}
}

class Dog extends Animal {


void bark() {
[Link]("Barking...");
}
}

class Test {
public static void main(String[] args) {
Dog d = new Dog();
[Link]();
[Link]();
}
}

🧠 Yahaan: - Animal = Parent


- Dog = Child
- extends keyword use hota hai

4️⃣ Polymorphism 🔄 (One thing, many forms)

🔹 Method Overloading (Compile Time)

class MathOp {
int add(int a, int b) {
return a + b;
}

int add(int a, int b, int c) {


return a + b + c;
}
}

Same method name, different parameters 👍

🔹 Method Overriding (Runtime)

class Parent {
void show() {
[Link]("Parent class");

3
}
}

class Child extends Parent {


void show() {
[Link]("Child class");
}

public static void main(String[] args) {


Parent p = new Child();
[Link]();
}
}

Output:

Child class

🎯 Runtime decision hota hai

⭐ Extra Important Concepts

🔹 Constructor

Object banate time automatically call hota hai.

class Demo {
Demo() {
[Link]("Constructor called");
}

public static void main(String[] args) {


Demo d = new Demo();
}
}

🔹 this keyword 👉

Current object ko refer karta hai.

class Test {
int x;

Test(int x) {

4
this.x = x;
}
}

🧠 OOP kyun important hai?


• Code reusable ♻️
• Easy maintenance 🛠️
• Real life modelling 👌
• Interviews & exams dono ke liye must ✅

You might also like