Thursday, June 4, 2015

Polymorphism Dynamic Method Dispatch

// Polymorphism is the ability to treat object with differences in behavior in a uniform way
// Polumorphism enables us to write programs that process objects that share
// the same superclass(directly or indirectly) as if they're all object of the superclass


public class PolymorphismDynamicMethodDispatch
{
public static void main(String[] args)
{
Animal a =new Human();
a.move();
}
}


class Animal
{
public void move()
{
System.out.println("Animal can Move. ");
}
}

class Human extends Animal
{
public void move()
{
System.out.println("Human can Move. ");
}
}


-----------------------------------------------------------------------------------------------------------------------



public class PolynomialDynamicMethodDispatch2
{
public static void main(String[] args)
{
Animal1 a =new Human1();
a.move();
}
}


class Animal1
{
public void move()
{
System.out.println("Animal can Move. ");
}
}

class Human1 extends Animal1
{

}



No comments:

Post a Comment