Labels

Tuesday, February 9, 2016

A Java program to show use of abstract class;

A Java program to show use of abstract class;

abstract class A{
    abstract void callme();
    void callmeto()
    {
        System.out.println("This is a concrete class");
    }
}
class B extends A{
    @Override
    void callme()
    {
        System.out.println("B's implementation on callme()");
    }
}
class C extends A{
    @Override
    void callme()
    {
        System.out.println("C's implementation of callme()");
    }
}
public class Abstract_demo {
    public static void main(String[] args)
    {
        B b=new B();
        C c=new C();
        b.callmeto();
        b.callme();
        c.callme();
    }

}

To run the program follow following step:-

  • Save code with name Abstract_demo.java
  • Open terminal and cmd and move to file location.
  • Compile: javac Abstract_demo.java
  • Run: java Abstract_demo




No comments:

Post a Comment