About polymorphism

Sorry for sending many questions but I will have an exam so ?have to.

My questions is that I think abstarct classes contribute polymorphism very much because they provide us to use an abstract method arbitrarily. So this means dynamic method binding, is not it ?

If I am false, please correct me.

[315 byte] By [samue-1a] at [2007-10-2 15:19:30]
# 1

Polymorphism is the capability of an action or method to do different things based on the object that it is acting upon.

Polymorphism allows a reference to denote objects of different types at different times during execution.

So Polymorphism is the result of dynamic method binding of overridden methods at runtime, and the binding is based on the actual type of the object, not the type of the reference.

Abhijaia at 2007-7-13 14:26:34 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks for your reply.There is something make me confused in your reply.the binding is based on the actual type of the object, not the type of the reference.I could not keep the ieda that you tried to give.Would you mind being more clear ?
samue-1a at 2007-7-13 14:26:34 > top of Java-index,Java Essentials,Java Programming...
# 3
And also this :Polymorphism is the result of dynamic method binding of overridden methods at runtime
samue-1a at 2007-7-13 14:26:34 > top of Java-index,Java Essentials,Java Programming...
# 4

> the binding is based on the actual type of the object, not the type of the reference.

class A {

void printHello() {

System.out.println("Hello from A");

}

}

class B extends A {

void printHello() {

System.out.println("Hello from B");

}

}

A obj;

obj = new B();

obj.printHello();

// *** Even if declared type of obj is A, binding will be made on actual type of obj which is B.

// *** So the ouput will be: "Hello from B"

jfbrierea at 2007-7-13 14:26:34 > top of Java-index,Java Essentials,Java Programming...
# 5
Thanks very much...
samue-1a at 2007-7-13 14:26:34 > top of Java-index,Java Essentials,Java Programming...
# 6
> Polymorphism is the result of dynamic method binding of overridden methods at runtime.In my example printHello() method from B overrides the one in A.
jfbrierea at 2007-7-13 14:26:34 > top of Java-index,Java Essentials,Java Programming...