Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access methods and instance variables of an abstract class ?  RSS feed

 
Rubbal Bhusri
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to access methods and instance variables of an abstract class ?
Whenever, lets say, a class is marked abstract and it got both abstract and non-abstract methods and since we cannot make objects of an abstract class(i.e. we can't instantiate abstract classes), So, how can we access non-abstract methods from outside the class ?
Can anyone please explain it with some fully functional example ?
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would have to instantiate it as a subclass. The fields should all be private and accessible via getXXX() methods. Look at my Bus class here, which is in response to a different question. So you are going to have to think how to generalise it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!