Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Ive saw the next paragraph in some computer science test and i'll hope i can get here a good explanation of what it means because i googled it for an hour and can't find anything..

"When we say Java language has virtual method calling we mean that in java applications the executed method is determined by the object type in run time"

What does it mean? can anyone explain it better?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
350 views
Welcome To Ask or Share your Answers For Others

1 Answer

The author of these lines used the c++ terminology of virtual.

A better terminology is dynamic binding / dynamic dispatch.

That means, that the object's dynamic type is "chosing" which method will be invoked, and not the static type.

For example: [pseudo code]:

class A {
  public void foo() { }
}
class B extends A { 
  public void foo() { }
}

when invoking:

A obj = new B();
obj.foo();

B.foo() will be invoked, and NOT A.foo(), since the dynamic type of obj is B.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...