This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes abstraction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "abstraction" Watch "abstraction" New topic


manohar reddy

Joined: Oct 13, 2007
Posts: 12
how to instatiate abstraction
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
An abstraction in Java is probably an interface or abstract class. You can't instantiate these. Both of these will fail:

x = new Runnable();
y = new AbstractList();

You can make a concrete class that implements the interface or extends the abstract class. The compiler will require the concrete class to provide all the abstract methods. Here's a concrete class you could instantiate:

And there's another tricky way to create a class right in line instead of defining it in its own file:

That looks a lot like we instantiated Runnable, an interface, but in fact we defined a tiny class with a run() method. It has no name so it's called anonymous, but it's a perfectly good little class as far as the compiler's concerned.

Does that all make sense?

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: abstraction
It's not a secret anymore!