wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes How to call a non-static non-abstract method in an abstract class from a static context? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to call a non-static non-abstract method in an abstract class from a static context?" Watch "How to call a non-static non-abstract method in an abstract class from a static context?" New topic
Author

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

Tarun Mohandas
Ranch Hand

Joined: Feb 12, 2013
Posts: 33

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

Joined: Oct 01, 2001
Posts: 2835
    
  11

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

Joined: Feb 12, 2013
Posts: 33

So, only through instances of sub-class a concrete method of an abstract class can be called. Ok thank you so much
 
Don't get me started about those stupid light bulbs.
 
subject: How to call a non-static non-abstract method in an abstract class from a static context?
 
Similar Threads
Why a Static method cannot refer to an instance variable?
lil explanation requied ..
Dan's single topic-anonymous classes.
abstract
abstract class instantiation