Can we have main method tn abstract class?

Yes, you can use the main method in abstract class. The main method is a static method so it is associated with Class, not with object/ instance. The abstract is applicable to the object so there is no problem if it contains the main method. In main method, you can not create an instance of the abstract class but you can instantiate other concrete class.


Here is a sample program


public abstract class TestAbstract {

public static void main(String[] args){

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

}

}



Post a Comment