0% found this document useful (0 votes)
3 views8 pages

Java OOPs

The document is a comprehensive overview of Object-Oriented Programming (OOP) concepts in Java, including classes, objects, encapsulation, inheritance, polymorphism, and abstraction. It provides real-life analogies to explain each concept and includes code examples to illustrate their implementation. Additionally, it offers bonus tips and encourages reader engagement through comments and sharing.

Uploaded by

koustavbaidya34
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)
3 views8 pages

Java OOPs

The document is a comprehensive overview of Object-Oriented Programming (OOP) concepts in Java, including classes, objects, encapsulation, inheritance, polymorphism, and abstraction. It provides real-life analogies to explain each concept and includes code examples to illustrate their implementation. Additionally, it offers bonus tips and encourages reader engagement through comments and sharing.

Uploaded by

koustavbaidya34
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 OOP SERIES

Object JAVA
Oriented
Programming OOP
Classes Inheritance Polymorphism Abstraction

Rajib Poddar
RP Software Engineer · Accenture
Java · Python · DSA · System Design

1/7

class JavaOOP { Swipe to learn →


Java Series
// Encapsulation · Inheritance · Polymorphism · Abstraction
static void main(String[] args) {
[Link]("Let's master OOP!");
}
}
01
JAVA OOP · SLIDE 2

Class & Object


Real Life Analogy

A floor plan is the CLASS — the actual house you live in is the OBJECT.
One blueprint → unlimited unique instances built from it. CLASS
&
Java OBJECT
class Car {
String brand;
int speed;

void accelerate() {
[Link](brand + "is going fast!");
} Code
} Foundation

// Creating Objects
Car myCar = new Car();
[Link] = "Toyota";
[Link](); // Toyota is going fast!

new keyword allocates memory on the heap for each object


Each object has its own copy of instance variables
A class is a user-defined reference data type in Java

@RajibPoddar · Java OOP Series 2/7


02
JAVA OOP · SLIDE 3

Encapsulation
Real Life Analogy

Your ATM card hides the bank backend. You use a PIN — not the server code.
private fields + public getters/setters = safe controlled access.
ENCAP-
Java
SULATION
class BankAccount {
private double balance; // hidden!

public void deposit(double amount) {


if (amount > 0) balance += amount;
}
Data Safety
public double getBalance() { & Control
return balance; // controlled access
}
}

private fields + public getters/setters is the standard Java pattern


Validation logic inside setters prevents invalid/corrupt data
Encapsulation = easier debugging and better maintainability

@RajibPoddar · Java OOP Series 3/7


03
JAVA OOP · SLIDE 4

Inheritance
Real Life Analogy

A child inherits eye color, surname from parents — yet adds their own personality.

INHERIT-
Single Multi-level ANCE
Dog extends Animal Grandparent→Parent→Child

Hierarchical Multiple
One parent, many children NOT via classes! Use interfaces

Code
Java Reusability
class Animal { void eat() { ... } }

class Dog extends Animal {


Dog() { super(); } // must be 1st line!
void bark() { [Link]("Woof!"); }
}
[Link](); // calling parent method

super() calls parent constructor — must be the FIRST line in child constructor
final class cannot be inherited (Java String class is final!)
@RajibPoddar · Java OOP Series 4/7
04
JAVA OOP · SLIDE 5

Polymorphism
Real Life Analogy
You behave differently at work, home & with friends — same person, different behavior =
polymorphism.
POLY-
Compile-time Runtime
MORPH-
ISM
Method Overloading Method Overriding
Same name, different parameters. Child redefines parent method.
Resolved by compiler. Resolved by JVM at runtime.

Java

// Overloading (compile-time) Flexibility


class Calc { & Power
int add(int a, int b) { return a+b; }
double add(double a, double b) { return a+b; }
}

// Overriding (runtime)
class Dog extends Animal {
@Override
void speak() { [Link]("Woof!"); }
}

Always use @Override — it catches mistakes where you accidentally overload instead of override
Overloading: same name, different params. Return type alone is NOT enough
5/7
@RajibPoddar · Java OOP Series
05
JAVA OOP · SLIDE 6

Abstraction
Real Life Analogy

You press the TV remote — you don't know how infrared works. Show WHAT, hide HOW.

ABSTRAC-
Abstract Class Interface TION
· 0–100% abstraction · 100% abstract (pre-Java 8)
· Can have constructors · No constructors
· Can have concrete methods · Java 8+: default/static methods
· Supports state (fields) · Multiple implementation

Java Hide
Complexity
abstract class Shape { abstract void draw(); }

interface Flyable { void fly(); }


interface Swimmable { void swim(); }

// Multiple interfaces — valid!


class Bird extends Animal implements Flyable, Swimmable {}

A class CAN implement multiple interfaces — Java's way of multiple inheritance


A class CANNOT extend multiple abstract classes (Diamond Problem)
@RajibPoddar · Java OOP Series 6/7
07
JAVA OOP · SLIDE 7

Bonus Key Points


final class static method instanceof

Cannot be inherited. Called without creating Checks object type


String is final in Java! an object instance. at runtime dynamically. BONUS
+
@Override this() super() CTA

Safety net — confirms Calls current class Calls parent class


you override, not overload. constructor. Must be 1st. constructor. Must be 1st.

Did this help you? Drop a comment below!


Save &
Which OOP concept confused you the most in college? Share!
Like · Repost to help others · Save for your next Java interview
Follow for more Java · Python · DSA · System Design content →
Next Post: Java Collections Framework — Complete Guide

Share this carousel to help your batchmates crack Java interviews!

@RajibPoddar · Java OOP Series 7/7


THE
JAVA OOP SERIES · COMPLETE

Thanks for END


Reading!
What you learned today:

Class & Object Encapsulation Inheritance

Polymorphism Abstraction Bonus Tips

Rajib Poddar
RP Software Engineer · Accenture
Connect with me on LinkedIn
Java · Python · DSA · System Design

7/7
Comment which OOP concept was your biggest aha! moment
Series End
Like · Repost to help others · Save · Follow Rajib Poddar for more
Next: Java Collections Framework →

You might also like