Abstract Practice Program 5

Abstract Practice Program 5

Program
abstract class A
{
    abstract void show();
    void disp()
    {
        System.out.println("This is abstract disp Method");
    }
}
class B extends A
{
    void show()
    {
        System.out.println("welcome");
    }
    void add()
    {
        System.out.println("This is B class Add Method");
    }
}
class C extends A
{
    void show()
    {
        System.out.println("java");
    }
}
public class Main
{
    public static void main(String arhs[])
    {
        A a=new B();
        a.show();
        a.disp();
        
        B b=new B();
        b.show();
        b.disp();
        b.add();
    }
}

Output:

welcome
This is abstract disp Method
welcome
This is abstract disp Method
This is B class Add Method
Note:
In the above example object created multiple times so memory allocated multiple times. To overcome this program down casting introduced. https://sateeshm.com/images/upcasting.jpeg


Abstract In Java



More Questions


142 . Abstract Practice Program 4
143 . Abstract Practice Program 5
144 . Down Casting Program
145 . Write a Java-program using super.(dot)
146 . Write a Java-program with out using super() no parameterized
147 . Write a Java-program with out using super() with parameterized
148 . Write a Java-program with using polymorphism
149 . Write a Java-program using static method overloading
150 . Write a Java-program using dynamic method overloading
151 . Write a Java-program using Constructor overloading
152 . Write a Java-program using static method overridding