• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inheritance help

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have trouble understanding why this is so...

This would print:
Method in Class B invoked
Class A
Why is this? whenever I use obj.varName, does it look in the declared type, not the actual object? As opposed to methods, which look to the actual object?
Thanks for your help,
Craig
------------------
boolean isDevilish(Human h)
{
if(h==CraigFlannagan)
return true;
else return false;
}
[This message has been edited by Craig Flannagan (edited October 21, 2001).]
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hehe, I like your signature. You are exactly correct Craig. The method that is invoked depends on the runtime type of the actual object. The variable that is accessed depends on the compile time type of the reference variable.
reply
    Bookmark Topic Watch Topic
  • New Topic