Introduction to Object –
Oriented Programming Paradigm
• Collection of Object
• Each object consists of data attributes and Methods
• Bottom Up Approach
• Data can be protected from accidental Modification
Example
Class Data Attributes Methods
Person ID Eat
Name Study
Age Sleep
Address
Features of OOP
• Class
• Object
• Abstraction
• Encapsulation
• Inheritance
• Polymorphism
1. Class
• A Class can be defined as an entity (separate unit) in which data and
function are put together
Syntax
class name_of_class
{
Private:
variable declaration;
function declaration;
Public:
variable declaration;
function declaration;
}
1. Class
• - A blueprint for creating objects
Syntax:
class Car {
Public:
int speed;
Private:
void drive() {
System.out.println("Driving...");
}
}
2. Object
• Object is as an instance(part) of a class
• Using object we can access the member variable
and member function of a class
• Object represent a person, place or any item
Syntax:
Class_name object_name;
Car myCar ;
myCar.drive();
3. Abstraction
• - Represent only essential features Hides internal implementation
• - Achieved using abstract classes or interfaces
Syntax:
Class student
{
Private:
Int rollno;
Char name[10];
Public:
Void input();
Void display();
};
Example
Student s1;
S1.input();
S1.display();
4. Encapsulation
• - Binding of data and methods into a single unit
• - Use private fields and public methods
Syntax:
class Student {
private int age;
public void setAge(int a) { age = a; }
public int getAge() { return age; }
}
5. Inheritance
• - Inheritance is a property by which the new classes are created using the
old classes
• Inheritance support hierarchical structure
• Old classes – base classes
• New classes – derived classes
Derived class inherit the properties of the base class
Syntax:
class Animal {
void eat() { System.out.println("Eating"); }
}
class Dog extends Animal {
void bark() { System.out.println("Barking"); }
}
6. Polymorphism
• - Many Structures
• Polymorphism is the ability to take more than
one form and refers to an operation exhibiting
different behavior in the different instances
• The name of the function remains same but it
can perform different tasks
• Example
• Class clean