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

Abstract class method  RSS feed

 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i access abstract class method, within non abstract class. ??Because it's not possible to create the object for abtract class within non abstract class.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call the method on an implementing class. For example:
 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public abstract class AbstractFoo {
public abstract void doSomething();
public int getTest(){
....
return i;
}
}

I want to access this non abstract getTest() method within Test class. How can i do that?
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you inherit a abstract class. Then all the non abstracts public & protected members are available to the subclass and the abstract methods are to be implemented in it.
 
Rudy Harianto
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as i know, you can do it with 2 ways:
1. you must instantiate the subclass of the abstract class
2. or declare the method 'static', so you can access it via abstract class directly (without instantiate it)

hope that help
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!