posted 23 years ago
You are right. An abstract class can not be instantiated. You would need to make a subclass of it, and instantiate the subclass.
Interfaces are a bit trickier. By definition all of the methods in an interface are abstract (they have no method body - no functionality). Actually some interfaces have NO methods at all. These exist only as "markers" to say "I am this sort of a thing".
Now when you say that an interface can not be instatiated, in the strictest sense that is true. However, there is the case of "upcasting" to an interface which you have to deal with.
Runnable is an interface. It is used to create objects that have threads.
You CAN NOT say:
Runnable r = new Runnable();
However if you have a class MyClass implements Runnable you CAN say:
Runnable r = new MyClass();
In this way you can end up with objects that appear to be instances of the interface, but actually hold objects of MyClass.
"JavaRanch, where the deer and the Certified play" - David O'Meara