This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to call subclass method?  RSS feed

 
Timothy Leong
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys
I have problem calling the method in the subclass. For example, I get error for the bold line.



what should i do to call the subclass method? Thanks
 
Stian Almaas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

You can't do that!
When you declare obj as a variable of type SuperA, you only get access to the methods defined in SuperA. You can override these methods in SubB1 or SubB2 to get a different behavior but to get to a "new" method defined in SubB1 you must declare an object of type SubB1.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cast obj to be of the type SubB1. Then you can call your subclass methods.
[ September 22, 2005: Message edited by: Paul Sturrock ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!