GLOBAL INSTITUTE OF MANAGEMENT & TECHNOLOGY
Presenting by – SHUVROJIT MAJUMDER (B.tech, CSE)
Year - 3rd Year Sem - 5th sem
Roll No. – 25900120006 Reg. No. – 202590100110010
Sub – OBJECT ORIENTED PROGRAMMING (OOPS)
Sub Code - PCC-CS503
INHERITANCE -
ENCAPSULATION
- POLYMORPHISM
Contents
⮚ INTRODUCTION
⮚ INHERITANCE
⮚ ENCAPSULATION
⮚ POLYMORPHISM
OOP – “Object Oriented Programming” . This is an engineering approach to
build / develop Software System .
“Object” means a real-world entity such as a pen, chair, table, computer,
etc. ”Object-Oriented Programming” is a methodology or paradigm to
design a program using classes and objects.
There are some Key-features of the oop Concept . They are -------
1. Abstraction
1. Inheritance
1. Encapsulation
1. Polymorphism
In this presentation we are discussing about the most important three(3)
Inheritance , Encapsulation , Polymorphism .
INTRODUCTION
Basic OOP Concept
•
Key - Features
•
•
INHERITANCE
⮚ Inheritance in Java is a mechanism in which one object acquires all the
properties and behaviors of a parent object .
⮚ The idea behind inheritance in Java is that we can create new classes, -
which are built upon existing classes. When we inherit from an existing
class, we can re-use methods and fields of the parent class. So that due
to inheritance Code reusability increases .
⮚ Inheritance represents the IS-A relationship which is also known as a –
parent - child relationship .
⮚ Program as example :
class Bike{
int wheel = 2;
}
class SportsBike extends Bike {
int maxSpeed = 180;
public static void main(String args[]){
SportsBike ktm = new SportsBike();
System.out.println(“No.of Wheel in ktm is:"+ktm.wheel);
System.out.println(“Max Speed of
ktm is:"+ktm.maxSpeed+”Km/h”);
}
}
Code
No.of Wheel in ktm is : 2
Max Speed of ktm is : 180 Km/h
Output
⮚ Terminologies used in Inheritance :
⮚ Class : A class is a group of objects which have common
properties. It is a template or blueprint of objects .
• Sub Class/Child Class: Subclass is a class which inherits the
other class. It is also called a derived class, extended class, or
child class.
• Super Class/Parent Class: Superclass is the class from where a
subclass inherits the features. It is also called a base class or a
parent class.
• Reusability : As the name specifies, reusability is a mechanism
which facilitates us to reuse the fields & methods of the existing
class when we create a new class.
• Types Of Inheritance :
ENCAPSULATION
class Name {
private int age; // Private is using to hide the data
public int getAge() { return age; } // getter
public void setAge(int age) {
this.age = age;
} // setter
}
class GFG {
public static void main(String[] args) {
Name n1 = new Name();
n1.setAge(19);
System.out.println(“The age of the person is: ”+
n1.getAge());
}
}
Code
The age of the person is : 19
Output
⮚ Encapsulation in Java is a process of wrapping code and data together
into a single unit, for example, a capsule which is mixed of several
medicines.
⮚ We can create a fully encapsulated class in Java by making all the data
members of the class private. Now we can use setter and getter methods
to set and get the data in it.
⮚ The Java Bean class is the example of a fully encapsulated class.
⮚ Program as example :
Advantages of Encapsulation in Java :
• By providing only a setter or getter method, we can make the
class read-only or write-only. In other words, you can skip the --
getter or setter methods.
• It provides us the control over the data. Suppose we want to set
the value of id which should be greater than 100 only, we can --
write the logic inside the setter method . We also can write the
logic not to store the negative numbers in the setter methods.
• It is a way to achieve data hiding in Java because other class will
not be able to access the data through the private data members.
• The encapsulate class is easy to test. So, it is better for unit testing.
• The standard IDE's are providing the facility to generate the ---
getters and setters. So, it is easy and fast to create an encapsulated
class in Java.
POLYMORPHISM
⮚ Polymorphism means having many forms. In simple words, we can
define
polymorphism as the ability of a message to be displayed in more than
one form.
⮚ Real - life Illustration: Polymorphism :
A person at the same time can have different
characteristics. Like a man at the same time is a
father, a Fruit Buyer, an employee. So the same
person possesses different behavior in different
situations. This is called polymorphism .
⮚ Polymorphism is considered one of the
important features of Object-Oriented
Programming. Polymorphism allows us to perform
a single action in different ways. In other words, polymorphism allows you
to define one interface and have multiple implementations. The word ---
“poly” means many and “morphs” means forms, So it means many forms.
⮚ Polymorphism is the ability of one object to be treated and used like ----
another object. As example, we treat duck as an animal and not just as a
duck. Similarly, we treat dog and cat also as animals.
Types of polymorphism :
• In Java polymorphism is mainly divided into two types:
(1) Compile-time Polymorphism /Static Polymorphism –
⮚ Overloading
⮚ Overriding
(2) Runtime Polymorphism / Dynamic Polymorphism –
It is also known as Dynamic Method Dispatch. It is a
process in which a function call to the overridden
method is resolved at Runtime. This type of polymor ---
phism is achieved by Method Overriding . Method
overriding, on the other hand, occurs when a derived
class has a definition for one of the member functions
of the base class. That base function is said to be
overridden.
THANK
YOU

Object Oriented Programming.pptx

  • 1.
    GLOBAL INSTITUTE OFMANAGEMENT & TECHNOLOGY Presenting by – SHUVROJIT MAJUMDER (B.tech, CSE) Year - 3rd Year Sem - 5th sem Roll No. – 25900120006 Reg. No. – 202590100110010 Sub – OBJECT ORIENTED PROGRAMMING (OOPS) Sub Code - PCC-CS503 INHERITANCE - ENCAPSULATION - POLYMORPHISM
  • 2.
    Contents ⮚ INTRODUCTION ⮚ INHERITANCE ⮚ENCAPSULATION ⮚ POLYMORPHISM
  • 3.
    OOP – “ObjectOriented Programming” . This is an engineering approach to build / develop Software System . “Object” means a real-world entity such as a pen, chair, table, computer, etc. ”Object-Oriented Programming” is a methodology or paradigm to design a program using classes and objects. There are some Key-features of the oop Concept . They are ------- 1. Abstraction 1. Inheritance 1. Encapsulation 1. Polymorphism In this presentation we are discussing about the most important three(3) Inheritance , Encapsulation , Polymorphism . INTRODUCTION Basic OOP Concept • Key - Features • •
  • 4.
    INHERITANCE ⮚ Inheritance inJava is a mechanism in which one object acquires all the properties and behaviors of a parent object . ⮚ The idea behind inheritance in Java is that we can create new classes, - which are built upon existing classes. When we inherit from an existing class, we can re-use methods and fields of the parent class. So that due to inheritance Code reusability increases . ⮚ Inheritance represents the IS-A relationship which is also known as a – parent - child relationship . ⮚ Program as example : class Bike{ int wheel = 2; } class SportsBike extends Bike { int maxSpeed = 180; public static void main(String args[]){ SportsBike ktm = new SportsBike(); System.out.println(“No.of Wheel in ktm is:"+ktm.wheel); System.out.println(“Max Speed of ktm is:"+ktm.maxSpeed+”Km/h”); } } Code No.of Wheel in ktm is : 2 Max Speed of ktm is : 180 Km/h Output
  • 5.
    ⮚ Terminologies usedin Inheritance : ⮚ Class : A class is a group of objects which have common properties. It is a template or blueprint of objects . • Sub Class/Child Class: Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class. • Super Class/Parent Class: Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class. • Reusability : As the name specifies, reusability is a mechanism which facilitates us to reuse the fields & methods of the existing class when we create a new class. • Types Of Inheritance :
  • 6.
    ENCAPSULATION class Name { privateint age; // Private is using to hide the data public int getAge() { return age; } // getter public void setAge(int age) { this.age = age; } // setter } class GFG { public static void main(String[] args) { Name n1 = new Name(); n1.setAge(19); System.out.println(“The age of the person is: ”+ n1.getAge()); } } Code The age of the person is : 19 Output ⮚ Encapsulation in Java is a process of wrapping code and data together into a single unit, for example, a capsule which is mixed of several medicines. ⮚ We can create a fully encapsulated class in Java by making all the data members of the class private. Now we can use setter and getter methods to set and get the data in it. ⮚ The Java Bean class is the example of a fully encapsulated class. ⮚ Program as example :
  • 7.
    Advantages of Encapsulationin Java : • By providing only a setter or getter method, we can make the class read-only or write-only. In other words, you can skip the -- getter or setter methods. • It provides us the control over the data. Suppose we want to set the value of id which should be greater than 100 only, we can -- write the logic inside the setter method . We also can write the logic not to store the negative numbers in the setter methods. • It is a way to achieve data hiding in Java because other class will not be able to access the data through the private data members. • The encapsulate class is easy to test. So, it is better for unit testing. • The standard IDE's are providing the facility to generate the --- getters and setters. So, it is easy and fast to create an encapsulated class in Java.
  • 8.
    POLYMORPHISM ⮚ Polymorphism meanshaving many forms. In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form. ⮚ Real - life Illustration: Polymorphism : A person at the same time can have different characteristics. Like a man at the same time is a father, a Fruit Buyer, an employee. So the same person possesses different behavior in different situations. This is called polymorphism . ⮚ Polymorphism is considered one of the important features of Object-Oriented Programming. Polymorphism allows us to perform a single action in different ways. In other words, polymorphism allows you to define one interface and have multiple implementations. The word --- “poly” means many and “morphs” means forms, So it means many forms. ⮚ Polymorphism is the ability of one object to be treated and used like ---- another object. As example, we treat duck as an animal and not just as a duck. Similarly, we treat dog and cat also as animals.
  • 9.
    Types of polymorphism: • In Java polymorphism is mainly divided into two types: (1) Compile-time Polymorphism /Static Polymorphism – ⮚ Overloading ⮚ Overriding (2) Runtime Polymorphism / Dynamic Polymorphism – It is also known as Dynamic Method Dispatch. It is a process in which a function call to the overridden method is resolved at Runtime. This type of polymor --- phism is achieved by Method Overriding . Method overriding, on the other hand, occurs when a derived class has a definition for one of the member functions of the base class. That base function is said to be overridden.
  • 10.