Abstraction
Abstraction is a concept which shows only important(essential) feature and hide background details.
In other way, abstraction shows only those things to user which are important and hides the background details.
for eg :- example of abstraction is tv remote, we press its button and see that channel get change, but we did not its internal processing.
we achieve abstraction in java by :-
ABSTRACT CLASS
we use abstract keyword for defining abstract class. That means a class which contain abstract keyword is a abstract class.
syntax
abstract class A{}
example :-
abstract class Print{
abstract void draw();
}
//In real scenario, implementation is provided by others i.e. unknown by end user
class A extends Print{
void draw(){System.out.println("A class implementing method of Print class");}
}
class B extends Print{
void draw(){System.out.println("B class implementing method of Print class");}
}
//In real scenario, method is called by programmer or user
class Abstraction{
public static void main(String args[]){
Print s=new B();//In real scenario, object is provided through method e.g. getShape() method
s.draw();
}
}
OUTPUT
B class implementing method of Print class
0 Comment(s)