This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes Why we can write Class inside interface  ? What's it use ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why we can write Class inside interface  ? What Watch "Why we can write Class inside interface  ? What New topic

Why we can write Class inside interface ? What's it use ?

sandip sangale

Joined: Jun 22, 2009
Posts: 15
elester johnson

Joined: Jan 31, 2011
Posts: 3

Sandeep! what exactly do you want to do regarding interfaces and classes. I'm going to assume you are doing this just to try everything possible with interfaces and classes, as long as you get their concepts and uses correct in the first place.
Coming back to your question - yes you can compile the program, but you can't run it as there is no main method in there. If you try a java blah, then the jvm gives a no main method error because it cant get a direct handle to the class as it is in the interface and as you may know you can't run an interface even though the main method is inside the class.
hope this helps.
Christophe Verré

Joined: Nov 24, 2005
Posts: 14687

9.5 Member type declarations.

I don't think I've seen this used anywhere.

By the way, you can execute the inner class via the interface :

>java -cp . InterfaceWithClass$InInterface

[My Blog]
All roads lead to JavaRanch
I agree. Here's the link:
subject: Why we can write Class inside interface ? What's it use ?
Similar Threads
is-a , has-a, is-like-a
Regarding Marker Interface?
Nullpointer exception in servlet
? extends String