File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to call a non-static non-abstract method in an abstract class from a static context?

 
Tarun Mohandas
Ranch Hand
Posts: 33
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that abstract classes cannot be instantiated. I also know that this code is perfectly legal.


and produces the output 5. But what should be done to call twoo() (if it is not static) from main()(static ofcourse). We obviously cannot use an object because abstract classes cannot be instantiated and also not do Twooo.twoo() because a non static method cannot be called from a static context. Is there a way to do that? If so how?
 
Greg Charles
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstract classes cannot be directly instantiated, but concrete classes that extend them can be. So if twoo() was not static, it could still be called through instances of a subclass. There is no way to call a non-static method through a static context, abstract or no.
 
Tarun Mohandas
Ranch Hand
Posts: 33
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, only through instances of sub-class a concrete method of an abstract class can be called. Ok thank you so much
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic