Constructors

class B
{
	B()
	{
		System.out.println("Ha ha ha. I am always called first");
	}
}

class A extends B
{
	A()
	{
	
		this("Samarth");
	}
	A(String s)
	{
		System.out.println("Hi this is "+s+" I am in Constructor A that has been called by this");
	}
}

class TestCons
{
	public static void main(String args[])	
	{
		A a=new A();		
	}
}

Leave a comment