Inheritance And Constructors In Java

Chapter: Inheritance Last Updated: 20-07-2016 03:19:17 UTC

Program:

            /* ............... START ............... */
                
class Base {
	Base() {
		System.out.println("Base Class Constructor Called ");
	}
}

class Derived extends Base {
	Derived() {
		System.out.println("Derived Class Constructor Called ");
	}
}

public class JavaConstructorInheritance {
	public static void main(String[] args) {
		Derived d = new Derived();
	}
}
                /* ............... END ............... */
        

Output

Base Class Constructor Called 
Derived Class Constructor Called 

Notes:

  • In Java, constructor of base class with no argument gets automatically called in derived class constructor.

Tags

Inheritance and constructors, Java

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
Java Super To Invoke Parent Class Constructor Inheritance 30-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
Multilevel Inheritance In Java Example Inheritance 22-09-2018
Super() In Java Example Inheritance 14-07-2016
Inheritance In Java Example Inheritance 20-07-2016

1