This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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
Author

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

sandip sangale
Greenhorn

Joined: Jun 22, 2009
Posts: 15
elester johnson
Greenhorn

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é
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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
Hello

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