0% found this document useful (0 votes)
7 views3 pages

Object Oriented Programming

Uploaded by

snyaabe
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)
7 views3 pages

Object Oriented Programming

Uploaded by

snyaabe
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
You are on page 1/ 3

Kalpesh Gupta

Object-Oriented Programming (OOP) Concepts - Presentation


Content

Object-Oriented Programming Concepts

Object-Oriented Programming (OOP) is a programming paradigm using objects and classes to organize
software design. It helps build scalable, reusable, and maintainable code.

What is OOP?

• A programming style based on the concept of "objects"


• Objects contain data (attributes) and behavior (methods)
• Helps in modeling real-world entities

Four Pillars of OOP

1. Encapsulation
2. Abstraction
3. Inheritance
4. Polymorphism

Encapsulation

• Wrapping data and methods into a single unit (class)


• Protects data from outside interference

Example (Java):

class Student {
private int age;
public void setAge(int a) { age = a; }
public int getAge() { return age; }
}

Abstraction

• Hiding internal implementation and showing only relevant details


• Achieved using abstract classes or interfaces

Example (Java):

abstract class Animal {


abstract void sound();
}
class Dog extends Animal {

1
void sound() { System.out.println("Bark"); }
}

Inheritance

• Mechanism where a child class inherits properties and behavior from a parent class
• Promotes reusability

Example (Java):

class Animal {
void eat() { System.out.println("This animal eats food"); }
}
class Dog extends Animal {
void bark() { System.out.println("Dog barks"); }
}

Polymorphism

• Ability to take many forms


• Supports method overloading and overriding

Example (Java):

class Animal {
void sound() { System.out.println("Animal sound"); }
}
class Cat extends Animal {
void sound() { System.out.println("Meow"); }
}

Class and Object

• Class: Blueprint of an object


• Object: Instance of a class

Example (Java):

class Car {
String color = "red";
}
Car myCar = new Car();
System.out.println(myCar.color);

Constructors

• Special methods used to initialize objects

2
• Called automatically when an object is created

Example (Java):

class Bike {
Bike() { System.out.println("Bike is created"); }
}

Access Modifiers

• Control the visibility of class members


• private , default , protected , public

Example (Java):

class Example {
public int a;
private int b;
protected int c;
}

Method Overloading & Overriding

• Overloading: Same method name with different parameters


• Overriding: Subclass provides specific implementation of a method in the parent class

Examples (Java):

// Overloading
int add(int a, int b) { return a + b; }
double add(double a, double b) { return a + b; }

// Overriding
class Parent { void show() {} }
class Child extends Parent { void show() {} }

Real-World Examples

• Encapsulation: ATM system (PIN protection)


• Abstraction: Driving a car (user doesn't see engine working)
• Inheritance: Animal → Dog, Cat
• Polymorphism: Payment method (Cash, Card, UPI)

You might also like