Java Super To Invoke Parent Class Constructor

Chapter: Inheritance Last Updated: 30-07-2017 14:22:35 UTC

Program:

            /* ............... START ............... */
                
class Animal {
	Animal() {
		System.out.println("animal is created");
	}
}

class Dog extends Animal {
	Dog() {
		super();
		System.out.println("dog is created");
	}
}

class TestSuper3 {
	public static void main(String args[]) {
		Dog dog = new Dog();
	}
}

                /* ............... END ............... */
        

Output

animal is created
dog is created

Notes:

  • Super keyword is used to invoke the parent class constructor.
  • A call to your parent class's empty constructor super() is done automatically. That's the reason you've never had to do it in your code.

Tags

Super To Invoke Parent Class Constructor, Java, Inheritance

Similar Programs Chapter Last Updated
Java Final Class Inheritance 02-08-2017
Java Final Method In Inheritance Inheritance 02-08-2017
Java Multilevel Hierarchical Inheritance Inheritance 01-08-2017
Java Super To Invoke Parent Class Method Inheritance 31-07-2017
Static And Dynamic Binding In Java Inheritance 24-03-2017
Java Overloaded Method To Print Array Inheritance 03-09-2016
Dynamic Method Dispatch In Java Example Inheritance 19-06-2016
Abstract Class In Java Example Inheritance 20-07-2016
Method Overriding In Java Example Inheritance 20-07-2016
Method Overloading In Java Example Inheritance 20-07-2016
Inheritance And Constructors In Java Inheritance 20-07-2016
Multilevel Inheritance In Java Example Inheritance 21-06-2017
Super() In Java Example Inheritance 14-07-2016
Inheritance In Java Example Inheritance 20-07-2016

1