File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt Example

 
Higor Zardo
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

Thanks!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you never created a cat object.
 
Gaurav Joshi
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you friends!!!
 
Higor Zardo
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Polymorphic invocation works only for overridden instance methods not variables
 
Higor Zardo
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sridhar row,
thank you very much!!!
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic