0% found this document useful (0 votes)
79 views

Object Oriented Programings (Oops)

Object oriented programming (OOP) incorporates features of structured programming with powerful new concepts like objects, classes, encapsulation, inheritance and polymorphism. The key features of OOP include: objects which represent entities, classes which define common properties and relationships, encapsulation which wraps data and functions into a class, inheritance which allows one class to acquire properties of another, and polymorphism which allows the same message to be interpreted differently.

Uploaded by

raj
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Object Oriented Programings (Oops)

Object oriented programming (OOP) incorporates features of structured programming with powerful new concepts like objects, classes, encapsulation, inheritance and polymorphism. The key features of OOP include: objects which represent entities, classes which define common properties and relationships, encapsulation which wraps data and functions into a class, inheritance which allows one class to acquire properties of another, and polymorphism which allows the same message to be interpreted differently.

Uploaded by

raj
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

OBJECT ORIENTED

PROGRAMINGS(OOPS)
*OOPS FEATURES
INTRODUCTION TO OBJECT ORIENTED
PROGRAMINGS(OOPS)

Definition:-
Object oriented programming is an approach to program
organization and development that attempts to eliminate
some of the pitfalls of conventional programming method by
incorporating the best of structured programming feature
with several powerful new concept
Working definition of opps as:-
“Object oriented programming is as an approach that
provide a way modular writing program by creating a
partition memory area for both the data and function
that can be used as templates for creating copy such
models on demand”
Features of object oriented programming languages:-

There are several feature of oops some of them is as follows:-


1.Object
2.Class
3.Data abstraction and encapsulation
4.Inheritance
5.Polymorphism
6.Dynamic binding
7.message passing
1.Object:-
Object oriented programming allows decomposition
of a problem into a number of entities called objects.
In another world :-
“Objects are the basic run time entities in an object
oriented system km represent a person a place a bank
account table of a table of data or any item that the
program has to handle.”
2.Class:-
A group of object that share common property and
relationship is known as class
In C ++ a class is a new data type that contain member
variable and member object are functions that operates on
the variables class are user defined data type and behave
like built-in type for a programming language.
Program:-
public class Name {
public static void main(String[] args) {
int a = 8;
System.out.println("RAJNISH RANJAN “+a);
}
}
Output:-
RAJNISH RANJAN 8
Here Name is a class .
3.Data abstractions and encapsulation:-
Abstraction:-
Abstractions refers to the act of representing essential feature
without including the background detail or explanations.
Encapsulation:-
Wrapping of data and function into a single unit called class is
known as encapsulation.
*Data encapsulation is the most striking feature of a class by this
feature the data is not accessible to the outside world only those
function which are wrapped in this class can access it.
*These functions provide the interface between the objects Data
and the program
4.Inheritance:-
That mechanism by which one object acquires all the property and
behavior of another object is known as inheritance.

That object or class which acquired property is known as child class or


derived class and or another is known as parent class object. When we
inherit from an existing class we can reuse method and Fields of the
parent class. Moreover we can add new method and Fields in our
current class also.
There are 5 types of inheritance :-
(i).Single inheritance
(ii).Multilevel inheritance
(iii).Hierarchical inheritance
(iv).Multiple inheritance
(v).Hybrid inheritance
(i).Single inheritance:-
when a subclass inherit the feature of only one super class
then that type of inheritance is known as single inheritance

Here in this figure the class B inheriting features of only one


super class a therefore it is known as single inheritance

A B
Example of single inheritance:-
class Father{
void height()
{
System.out.println("\t Taller in height.");
}
}
class Son extends Father{
void body() {
System.out.println("\t Body is fat.");
}
}
public class SingleInheritance {

public static void main(String[] args) {


Son s = new Son();
System.out.println("\t Personality of son:-");
s.height();
s.body();
}
}
OUTPUT:-
Personality of son:-
Taller in height.
Body is fat.
(ii).Multilevel inheritance:-
When a class C inheriting the property of a subclass B and the
subclass B also inherited the features of a super class A then this
type of inheritance is known as multilevel inheritance

c
A B
Example of Multilevel inheritance:-
class GrandFather{
void Behaviour()
{
System.out.println("\t Good behaviour .");
}
}
class Father extends GrandFather{
void height()
{
System.out.println("\t Taller in height.");
}
}
class Son extends Father{
void body() {
System.out.println("\t Body is fat.");
}
}
public class MultilevelInheritance1 {
public static void main(String[] args) {
Son s = new Son();
System.out.println("\tPersonality of son:-"); OUTPUT:-
s.Behaviour();
s.height();
Personality of son:-
s.body(); Good behaviour .
} Taller in height.
Body is fat.
(iii).Hierarchical inheritance:-
when more than one subclass inheriting the property and features
of only one super class 10 that type of inheritance is known as
hierarchical inheritance
A

B C D
Example of Hierarchical inheritance:-
class Father2{
void height()
{
System.out.println("\t Taller in height.");
}
}
class Son2 extends Father2{
void body() {
System.out.println("\t Body is fat.");
}
}
class Doughter extends Father2{
void body() {
System.out.println("\t Body is slim.");
}
}
public class Hierarchical_Inheritance {
public static void main(String[] args) {
Son2 s = new Son2();
System.out.println("\tPersonality of son:-"); OUTPUT:-
s.height();
s.body();
Personality of son:-
Doughter d = new Doughter(); Taller in height.
System.out.println("\tPersonality of Doughter:-"); Body is fat.
d.height();
d.body(); Personality of Doughter:-
} Taller in height.
}
Body is slim.
(iv).Multiple inheritance:-
when one subclass having more than one super class and inherit all
features from all parent class then that type of inheritance is known as
multiple inheritance.
But to reduce the complexity and simplicity of the language multiple
inheritance is not supported in Java and achieved by interface

A B

C
(v).Hybrid inheritance:-
hybrid inheritance is a mix of two or more of the above type of
inheritances. It is also not supported and achieved by interface only.

A B C

X Y
5.Polymorphism :-
Polymorphism is a Greek term means the ability to take
more than one form.
That property by which we can send the same message to
the object of several different class and each object can
respond in a different way depending on its class is known as
polymorphism.
Through polymorphism we can send such a message without
knowing to which of class the object belongs.

There are two type of polymorphism :-


(i).Compile time polymorphism
(ii).Run time polymorphism
(i).Compile time polymorphism :-
Compile time polymorphism means that an object is bounded to its
function call at compile time.
Example for compile time polymorphism:-
class Sum{
int sum(int x, int y)
{
return (x + y);
}
int sum(int x, int y, int z)
{
return (x + y + z);
}
double sum(double x, double y)
{
return (x + y);
}
}
public class CompileTimePoly {
public static void main(String[] args) {
Sum = new Sum();
System.out.println("int sum(x,y) = "+s.sum(10, 20));
System.out.println(" int sum(x,y,z) = "+s.sum(10,
20, 30));
OUTPUT:-
System.out.println("double sum(x,y) = int sum(x,y) = 30
"+s.sum(10.5, 20.5));
}
int sum(x,y,z) = 60
} double sum(x,y) = 31.0
(ii).Run time polymorphism:-
In runtime polymorphism the object is linked to the function call by
lately at runtime.

You might also like