Write a program in java to demonstrate abstract class using instance member, static data member, static block, static method, default constructor, parameterize constructor, abstract method, non-abstract method?

abstract class Abs

{

                int a;      //Instance Member

                static int b;          //Static Data Member

                static     //Static Block

                {

                                System.out.println("Hello Abs Class");

                }

                public static void hello() //Static Method

                {

                                System.out.println("Hello Abs");

                }

                public Abs()        //Default Constructor

                {

                                System.out.println("Default Abs");

                }

                public Abs(int x)               //Parameterize Constructor

                {

                                System.out.println("One Parameterize Abs");

                }

                public abstract void display();     //Abstract Method

                public void hi()  //Non-Abstract Method

                {

                                a=7;

                                b=9;

                                System.out.println(a+" + "+b+" = "+(a+b));

                }

}

class MainAbstract extends Abs

{

                public MainAbstract()

                {

                                System.out.println("Hello Defaut Main");

                }

                public MainAbstract(int x)

                {

                                super(x);

                                System.out.println("Hello One Parameterize Main");

                }

                public void display()

                {

                                System.out.println("Hello Display");

                }

                public static void main(String []arg)

                {

                                MainAbstract x=new MainAbstract();

                                MainAbstract y=new MainAbstract(5);

                                x.display();

                                Abs.hello();

                                x.hi();

                }

}

demonstrate abstract class using instance member, static data member, static block, static method, default constructor, parameterize constructor, abstract method, non-abstract method.PNG

, , , , , , , , , , , , , ,

Leave a Reply