wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt Example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt Example" Watch "Doubt Example" New topic
Author

Doubt Example

Higor Zardo
Ranch Hand

Joined: Feb 16, 2008
Posts: 59


Why this code print "bark bark" and not "meow bark"?
I dont understand.

Thanks!
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Because you never created a cat object.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Gaurav Joshi
Greenhorn

Joined: Mar 08, 2008
Posts: 18
Always remember the actual object created, Dog in this example.At run time jvm will invoke the overrided method of actual object(Polymorphism)

Here Animal and Cat are the references
Higor Zardo
Ranch Hand

Joined: Feb 16, 2008
Posts: 59
Thanks you friends!!!
Higor Zardo
Ranch Hand

Joined: Feb 16, 2008
Posts: 59
Just more one doubt.
Reference variable always is modified and never the object or object can be modified too in some circustance?
Higor Zardo
Ranch Hand

Joined: Feb 16, 2008
Posts: 59
Look,



The output of this code is: foobarfoo
But the object in "((TesteConver2)s).FOO" is not Sub? then i think that Sub should be call because polymorphism. not?

Thanks to help me.
sridhar row
Ranch Hand

Joined: Jan 16, 2008
Posts: 162
Polymorphic invocation works only for overridden instance methods not variables
Higor Zardo
Ranch Hand

Joined: Feb 16, 2008
Posts: 59
sridhar row,
thank you very much!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt Example