//to demonstrate the idea of constructor chain

class ChainCon{
	public ChainCon(){
		System.out.println("ChainCon constructor 1");	
	}
}

class ChainCon2 extends ChainCon{
	public ChainCon2(){
		System.out.println("ChainCon constructor 2");	
	}
}

class ChainCon3 extends ChainCon2{
	public ChainCon3(){
		//super();
		System.out.println("ChainCon constructor 3");	
	}
	
	public static void main(String[] args){
		ChainCon3 cc = new ChainCon3();	
	}
}


/*******************************************************/
// The following part demonstrate overriding

class A{
	int x = 10;
	void output(){
		System.out.println("inside A: "+ (x+10));	
	}	
}

class B extends A{
	void output(){
		System.out.println("inside B "+ (x*10));	
	}
	
	public static void main(String[] args){
		A a = new A();
		a.output();
		B b = new B();		
		b.output();
		a=b;
		a.output();	
		//a = new A();
		b=(B)a;
		b.output();
	}
}

/*******************************************************/
// the following demonstrate dynamic binding

class Shape{
	void draw(){
		System.out.println("drawing shape");	
	}
	//abstract void draw();
}

class Circle extends Shape{
	void draw(){
		System.out.println("drawing circle");	
	}
}

class Square extends Shape{
	void draw(){
		System.out.println("drawing square");	
	}
	
	public static void main(String[] args){
		Shape[] s = new Shape[3];
		s[0] = new Shape();
		s[1] = new Circle();
		s[2] = new Square();
		for(int i=0;i<3;i++)
			s[i].draw();	
	}
}
