• 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

overriding/poly morphic question

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

why does the comented line give me an error even though the class of l3 is tube why is it saying that it cannot find the test method in light . i thought it would use the one in tube
[ Jess Added UBB [CODE] tags to preserve whitespace, improve readibility ]
[ June 06, 2002: Message edited by: Jessica Sant ]
 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because l3 is a reference to a superclass Light which doesn't have a test method. To call test() like this it has to be overridden. Since it is not overridden and you want to call the method in the subclass a cast is definitly needed.
Hope this helps.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tosin Adedoyin:

why does the comented line give me an error even though the class of l3 is tube why is it saying that it cannot find the test method in light . i thought it would use the one in tube
[ Jess Added UBB
to avoid compiler errors

 
Tosin Adedoyin
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you but i thought that when a method is invoked on an object using a reference , it is the class of the current object denoted by the reference not the type of the reference that determines which method implementation will be executed ? so i thought the method test in tube should be called becase l3 is of class Tube
 
reply
    Bookmark Topic Watch Topic
  • New Topic