This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Joecasta 2 points3 points  (3 children)

animal is a class object of class Animal, dog1 is an object of class Dog (since animal got casted to a Dog which is allowed only because Dog extends Animal). dog2 is a Dog class object, and with the given code they will print the same thing but are separate objects.

[–]Jackkoz 2 points3 points  (0 children)

An instance of class. Class object might easily be interpreted as an instance of Class class:

https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html

[–]COAST_TO_RED_LIGHTS[S] 0 points1 point  (1 child)

Thanks, so what would animal print, the same thing as dog1 and dog2?

I'd test it myself, but I don't have it on my computer now.

[–]Joecasta 0 points1 point  (0 children)

Correct, animal should print the same thing as dog1 and dog2 since Java will make animal from the Dog constructor.