Call Parameterized Constructor in Inheritance

class Base5 
{
	public Base5() 
	{
		System.out.println("Default constructor in Base4");
	}
	public Base5(int i) 
	{
		System.out.println("Constructor with one int parameter in Base5");
	}
	public Base5(int i, int j) 
	{
		System.out.println("Constructor with two int parameter in Base5");
	}
}
public class InheritanceDemo3 extends Base5 
{
	public InheritanceDemo3() 
	{
		System.out.println("Default constructor in InheritanceDemo2");
	}
	public InheritanceDemo3(int i) 
	{
		// call one int parameter from base class
		// this statement must be first statement in constructor
		super(i);
		System.out.println("Constructor with one int parameter in derived class");
	}
	public InheritanceDemo3(int i, int j) 
	{
		// call two int parameters from base class
		// this statement must be first statement in constructor
		super(i, j);
		System.out.println("Constructor with two int parameter in derived class");
	}
	public static void main(String[] args) 
	{
		new InheritanceDemo3();
		new InheritanceDemo3(10);
		new InheritanceDemo3(100, 200);
	}
}
/*
 * output - Default constructor in Base4 Default constructor in InheritanceDemo2
 * Constructor with one int parameter in Base5 Constructor with one int
 * parameter in derived class Constructor with two int parameter in Base5
 * Constructor with two int parameter in derived class
 */

Download

Java Basics Examples

Default constructor example
Parameterized constructor example
Call other constructor
Command Line argument example
Display sum of Command Line arguments
Foreeach example with int data type [ Only in JDK 1.5 ]
Foreeach example with String data type [ Only in JDK 1.5 ]
Foreeach example with user defiend [ Only in JDK 1.5 ]
Simple Inheritance
Call default constructor in Inheritance
Call parameterized constructor in Inheritance
Java Beans example
Overload method in one class
Overload method in inheritance
Override example , super keyword
super keyword example
override toString method


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code