Java

Topic: Abstract Class and Interfaces

Can Abstract Class have constructors? Can interfaces have constructors?

Abstract class's can have a constructor, but you cannot access it through the object, since you cannot instantiate abstract class. To access the constructor create a sub class and extend the abstract class which is having the constructor.Examplepublic abstract class AbstractExample {public AbstractExample(){System.out.println("In AbstractExample()");}}public class Test extends AbstractExample{public static void main(String args[]){Test obj=new Test();}}

Browse random answers: