1class Parentclass
2{
3 //no-arg constructor
4 Parentclass(){
5 System.out.println("no-arg constructor of parent class");
6 }
7 //arg or parameterized constructor
8 Parentclass(String str){
9 System.out.println("parameterized constructor of parent class");
10 }
11}
12class Subclass extends Parentclass
13{
14 Subclass(){
15 /* super() must be added to the first statement of constructor
16 * otherwise you will get a compilation error. Another important
17 * point to note is that when we explicitly use super in constructor
18 * the compiler doesn't invoke the parent constructor automatically.
19 */
20 super("Hahaha");
21 System.out.println("Constructor of child class");
22
23 }
24 void display(){
25 System.out.println("Hello");
26 }
27 public static void main(String args[]){
28 Subclass obj= new Subclass();
29 obj.display();
30 }
31}