1.

Can we declare a class as Abstract without having any abstract method?

Answer»

An abstract class is a class that cannot be instantiated on its own. It can be created in Java using the abstract keyword.

A class can be declared as an abstract class without having an abstract method. In that case, the class created cannot be instantiated but can be inherited.

A PROGRAM that demonstrates this is given as follows:

abstract class BaseClass {        void DISPLAY()    {        System.out.println("INSIDE the BaseClass");    } } class DerivedClass extends BaseClass { } public class Demo {    public static void MAIN(String args[])    {        DerivedClass obj = NEW DerivedClass();        obj.display();    } }

The output of the above program is as follows:

Inside the BaseClass


Discussion

No Comment Found