Java-Constructor Execution

Constructor Execution

A super class constructor should be executed before a subclass constructor is executed. Only then, an object of a subclass will be properly initialized.

Program

1

Program Source

class Super {
 
    Super()
    {
        System.out.println("Super class constructor");
    }    
}

class Sub extends Super{
 
    Sub()
    {
        System.out.println("Sub class constructor");
    }
}

public class Javaapp {

    public static void main(String[] args) {
     
        Sub obj = new Sub();
    }
}

Leave a Comment