Method Level Abstraction
Method Level Abstraction
Method Level Abstraction
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.
Encapsulation:
The process of Encapsulating data and corresponding methods into a single module.
(or)
(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.)
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 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.
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:
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.
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.
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)
(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
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.