Sie sind auf Seite 1von 5

OOPS

Abstraction
Encapsulation
Polymorphism
Inheritance

Abstraction:
Hide internal implementation and just highlight the set of services, is called abstraction.

{or}
The process of visualizing necessary data and hiding unnecessary data is called Abstraction.

(or)
The process of Retrieving\Extracting Essential details without considering hidden details is
called Abstraction.
In Java application we are able to achieve Abstraction at three levels

1) Method Level Abstraction: The process of hiding method level variables is called
Method Level Abstraction
2) Class Level Abstraction: The process of hiding class level variables and methods is called
Class Level Abstraction.
3) Package Level Abstraction: The process of hiding class and interfaces is called Package
Level Abstraction.

The main advantages of Abstraction are:

We can achieve security as we are not highlighting our internal implementation.


Enhancement will become very easy because without effecting end user we can able to
perform any type of changes in our internal system.
It provides more flexibility to the end user to use system very easily.
It improves maintainability of the application.

Encapsulation:
The process of Encapsulating data and corresponding methods into a single module.

(or)

The process of Binding data and coding part is called Encapsulation.

(or)
Encapsulation=Data Hiding + Abstraction.

(Data hiding means our internal data should not go out directly that is outside person cant access
our internal data directly.)

In Java application we are able to achieve Encapsulation at two levels

1) Method Level Encapsulation: The process of binding method level variables and coding
part is called Method Level Encapsulation.
2) Class Level Encapsulation: The process of binding class level variables and method
coding part is called Class Level Encapsulation.

The main advantages of encapsulation are:

We can achieve security.


Enhancement will become very easy.
It improves maintainability of the application.
It provides flexibility to the user to use system very easily.

The main disadvantage of encapsulation is it increases length of the code and slows
Down execution.

NOTE: Both Abstraction and Encapsulation are Co-Existed both will provide Security for
the application data in java application.

(Co-Existed means one is available automatically another one is available)

Inheritance:
The Process of getting variables and methods from one class to another class is called
Inheritance.
It is also known as IS-A relationship.
The main advantage of Inheritance (IS-A relationship) is to improve code
reusability.
Inheritance concept always follows Logical Memory Management this memory
management says feature of Base class exist in Derived class without taking any
space and without taking any explicit development time.
Inheritance concept also known as Sub classing, Derivation, Extendable class,
Reusability,

Advantages of Inheritance:

Application Development time is less.


Application memory space is less.
Application Execution time is less.
Application performance is Enhance.
Redundancy of code is minimized.
We are able to get Slogan of java.

Inheritance Types\Reusable techniques:

There are two types of Inheritance at basic level of Object organization

1) Single Inheritance
2) Multiple Inheritance

1) Single Inheritance: The process of getting variables from one super class to one\more
sub classes is called Single inheritance.

Single inheritance is supported by java.

2) Multiple Inheritances: The process of getting variables and methods from more than
one supper class to one or more no. of sub classes is called Multiple Inheritance.

Multiple Inheritance not supported by java at class level but interface level supported.

3) Multilevel Inheritance: It is combination of single inheritance in more than one level


4) Hierarchical Inheritance: It is combination of single inheritances in a particular
Architecture.
5) Hybrid Inheritance: It is combination of single and multiple inheritances.

NOTE: Java supports Single, multilevel, hierarchical interfaces by both classes and interfaces
concept.

Polymorphism:
The process of representing one form in multiple forms is known as Polymorphism.

(or)

Same name with different forms is the concept of polymorphism.

(or)

Polymorphism is Greek word where poly means many and morphsum means forms

One thing is existing in more than one form then it is called polymorphism.
In java programming polymorphism principle can be implemented by using two concepts

Method overloading

Method Overriding

There are two types Polymorphisms

1) Static/Compile time/early Polymorphism: If polymorphism existed in compile time


then that polymorphism is called Static polymorphism.
Ex: Method overloading

2) Dynamic/Rue time/late Polymorphism: If Polymorphism existed in runtime then that


polymorphism is called Dynamic Polymorphism
Ex: Method overriding

OVERLOADING vs. OVERRIDING

Overloading:
Two methods are said to be overload if and only if both having the same name but
different argument types.

Ex:

sanju(int);
sanju(floate);
sanju(duble);

Having the same name and different argument types is called method overloading.
All these methods are considered as overloaded methods.
Having overloading concept in java reduces complexity of the programming.

Example:

class Test
{
public void methodOne()
{
System.out.println("no-arg method");
}
public void methodOne(int i)
{
System.out.println("int-arg method"); overloaded methods
}
public void methodOne(double d)
{
System.out.println("double-arg method");
}
public static void main(String[] args)
{
Test t=new Test();
t.methodOne();//no-arg method
t.methodOne(10);//int-arg method
t.methodOne(10.5);//double-arg method
}
}
In overloading compiler is responsible to perform method resolution(decision) based on
the reference type. Hence overloading is also considered as compile time
polymorphism (or) static (or)early biding.

Das könnte Ihnen auch gefallen