File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Inheritance , dynamic binding? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance , dynamic binding?" Watch "Inheritance , dynamic binding?" New topic

Inheritance , dynamic binding?

Zeeman Chen

Joined: Oct 30, 2003
Posts: 9
I cannot understand what's going on behind the code.
the result is
if I hadn't written :
v =d; // upcasting , safe
runtime error since d= (Dog)v; downcasting unsafe.

who can tell me what happend in memory after the following two
thanks in advance!
v= d;
d = (Dog)v;

If a man take no thought at what is distant, he will find sorrow near at hand. ~ Confucius
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
One way to see for yourself how things work here is to rename move1(), move2(), and move3() all to move(). Then add some calls to move() from main() like this:

Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Inheritance , dynamic binding?
It's not a secret anymore!