ABSTRACTION
Abstraction: hiding of method implementation and showing only method signature is called "Abstraction".
Program in JAVA:
public interface Distance
{
public void go();
}
class Walk implements Distance //class is hided for user
{
public void go() //implementation is also hided
{
System.out.println("go and save your life..");
}
}
class Helper // class is used to create an object for an user
{
public static Distance helpMethod()
{
Distance d1 = new Walk(); //here we use upcasting to hide the method
return d1; // implementation
}
}
class Main
{
public static void main (String [] args)
{
Distance d2 = Helper.helpMethod();
d2.go();
}
}
No comments:
Post a Comment