Defining an abstract class without any abstract methods Defining an abstract class without any abstract methods java java

Defining an abstract class without any abstract methods


Of course.

Declaring a class abstract only means that you don't allow it to be instantiated on its own.

Declaring a method abstract means that subclasses have to provide an implementation for that method.

The two are separate concepts, though obviously you can't have an abstract method in a non-abstract class. You can even have abstract classes with final methods but never the other way around.


Yes you can do it. Why don't you just try doing that?


Yes you can. The abstract class used in java signifies that you can't create an object of the class. And an abstract method the subclasses have to provide an implementation for that method.

So you can easily define an abstract class without any abstract method.

As for Example :

public abstract class AbstractClass{    public String nonAbstractMethodOne(String param1,String param2){        String param = param1 + param2;        return param;    }    public static void nonAbstractMethodTwo(String param){        System.out.println("Value of param is "+param);    }}

This is fine.