Monday, August 29, 2011

Abstract Method Example


/*To make overridden compulsory we make the method abstract with the help of abstract keyword.
When we make a method abstract then this method must be override in sub class.*/

//SuparClass.java
public abstract class SuparClass
{
abstract void Display(); /*abstract method don't has anybody. But we must have to define it in sub class.*/
}

//SubClass.java
public class SubClass extends SuparClass
{
void Display()
{
System.out.println("I am in subclass");
}
}

//MainClass.java
public class MainClass
{
public static void main(String args[])
{
SubClass sub = new SubClass();
sub.Display();
}
}


Output =>
I am in subclass

No comments:

Post a Comment