aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes overriding/poly morphic question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "overriding/poly morphic question" Watch "overriding/poly morphic question" New topic
Author

overriding/poly morphic question

Tosin Adedoyin
Ranch Hand

Joined: Nov 09, 2001
Posts: 43

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 ]
Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
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.


Thanks,<br />Thiru<br />[SCJP,SCWCD,SCBCD]
Anna Dow
Greenhorn

Joined: Jun 04, 2002
Posts: 18
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

Joined: Nov 09, 2001
Posts: 43
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: overriding/poly morphic question