Polymorphism

public class Car
{
	public void f1()
	{
		System.out.println("f1 in Car ...");
	}

	public void f2()
	{
		System.out.println("f2 in Car ...");
	}
}
			
public class Buick extends Car
{
	public void f2()
	{
		System.out.println("f2 in Buick ...");
	}

	public void f3()
	{
		System.out.println("f3 in Buick ...");
	}
}
			
public class CarTest
{
	public static void main(String args[])
	{
		Car c = new Car();
		Buick b = new Buick();

		c.f1();//f1 in Car ...
		c.f2();//f2 in Car ...

		b.f1();//f1 in Car ..., inherited from Car
		b.f2();//f2 in Buick ..., dynamic binding
		b.f3();//f3 in Buick ...

		Car b2 = new Buick();

		b2.f1();//f1 in Car ...
		b2.f2();//f2 in Buick ...
		//b2.f3();//error, Car has no f3
		((Buick)b2).f3();//f3 in Buick ..., cast data type to Buick
	}
}
			
Static Binding
public class Car
{
	public static void display()
	{
		System.out.println("Car");
	}
}
			
public class Buick extends Car
{
	public static void display()
	{
		System.out.println("Buick");
	}
}
			
public class CarTest
{
	public static void main(String args[])
	{
		Car c = new Car();
		Car b = new Buick();

		c.display();//Car
		b.display();//Car
	}
}
			
Dynamic Binding
public class Car
{
	public void display()
	{
		System.out.println("Car");
	}
}
			
public class Buick extends Car
{
	public void display()
	{
		System.out.println("Buick");
	}
}
			
public class CarTest
{
	public static void main(String args[])
	{
		Car c = new Car();
		Car b = new Buick();

		c.display();
		b.display();
	}
}
			
Reference