*
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why we can write Class inside interface ? What's it use ?
 
Similar Threads
Regarding Marker Interface?
Casting
Nullpointer exception in servlet
is-a , has-a, is-like-a
? extends String