Abstraction
* Abstraction is the process of hiding the implementation and show only the functionality to the user.* A class declared as a abstract its called abstract class.It need to be extends and implements its method .It can't be instantiated.
* A method declared as a abstract its does not have any implementation its called abstract method.
* An abstract class can have data member, abstract method, method body, constructor and even main() method.
* The abstract class can also be used to provide some implementation of the interface. In such case, the end user may not be forced to override all the methods of the interface.
EXAMPLE
// The abstract class can also be used to provide some implementation of the interface. In such case,
// the end user may not be forced to override all the methods of the interface.
interface Sports{
void Football();
void Tennis();
}
// A class declared as a abstract its called abstract class.It need to be extends and implements its method .It can't be instantiated.
public abstract class India implements Sports {
// An abstract class can have data member, abstract method, method body, constructor and even main() method.
public India() {
// TODO Auto-generated constructor stub
System.out.println("Constructor");
}
void IPL(){
System.out.println("IPL");
}
public void Football(){
System.out.println("Football");
}
// A method declared as a abstract its does not have any implementation its called abstract method.
abstract void Players();
}
class Cricket extends India{
@Override
void Players() {
// TODO Auto-generated method stub
System.out.println("India");
}
@Override
public void Tennis() {
// TODO Auto-generated method stub
System.out.println("Tennis");
}
}
class BCCI extends India{
@Override
void Players() {
// TODO Auto-generated method stub
System.out.println("India X1");
}
@Override
public void Tennis() {
// TODO Auto-generated method stub
System.out.println("Tennis not available");
}
public static void main(String args[]){
India in = new Cricket();
in.Players();
in.IPL();
in.Football();
in.Tennis();
India ind = new BCCI();
ind.Tennis();
}
}
|
DOWNLOAD ABSTRACTION SAMPLE
No comments:
Post a Comment