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

Concrete Methods in Abstract class  RSS feed

 
sirisha makkapati
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How we can Call Concrete methods in Abstract class,we can do this By Declaring it as Static Method.
Is Any other solution for this
Any One Please Tell me
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to create a class that fully extends the abstract class (implementing all abstract methods from the abstract class) and then call the method on an instance of this new class.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a class is abstract that implies the class is not fully implemented. Typically at least one method in the class is abstract too.

You declare it abstract to enforce the implementation of the method before the class ca be used. So you cannot instantiate an abstract class, and logically you cannot invoke an instance method in an abstract class, irrespective of the method be abstract or not.

Of course, if you declare the method as static you can invoke without any problem. As long as you are not suggesting an abstract static method, which by chance is not possible either, since there is no way to inherit an static method, and therefore there is no point in declaring it abstract.

Now, you could create an anonymous class that implements the method in abstract class and this way use it.

For instance:



You coud even do it this way:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!