Profile image for phoenix studio phoenixstudio
25 April 2012
Language
Java
Tags
inheritance

Inheritance

1 class Parent{ 2 public Parent(){//(3) 3 4 System.out.println("Parent constructor");//(4) 5 }; 6 7 public Parent(String s){ 8 System.out.println("String entered in child class is:"+s); 9 } 10 11 } 12 13 class Child extends Parent{ 14 public Child(){ //(2) 15 16 //super();//default constructor of parent called - empty param 17 super("Hello,java");//appropriate constuctor of parent called. 18 System.out.println("Child constructor");//(5) 19 }; 20 } 21 22 public class TestChild{ 23 public static void main(String[] args){ 24 Child anak = new Child(); //(1)->go to child 25 }//(6) 26 }//(7) 27 28 //execution sequence denoted using number in parentheses

Comments