aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can a class be declared inside a interface? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Can a class be declared inside a interface?" Watch "Can a class be declared inside a interface?" New topic
Author

Can a class be declared inside a interface?

Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

I got this question from here


What is the usage of this kind of declaration?


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Lokesh Duseja
Greenhorn

Joined: Jul 03, 2010
Posts: 5
Yes you can!!

You can even implement this interface and make an object of this "inner static" class... see the code below




My friend.... you were too kind to declare that inner class "public static" and the interface as "abstract"... these are implicit!!

I think my explanation is correct..... if not, blame it to the beer..... normally i don't "drink and drive"!!


Sun Certified Java Programmer -6.0
IBM Websphere MQ Series System Administrator - 5.3
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Thanks a lot...BTW, Can we 'override' that class declaration in our implementation class?
Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 383

no you can't because ... it is implicitly final and static


http://plainoldjavaobject.blogspot.in
Lokesh Duseja
Greenhorn

Joined: Jul 03, 2010
Posts: 5
i did not get the last question..... overriding a class? i only heard of overriding method....
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Lalit Mehra wrote:no you can't because ... it is implicitly final and static


OMG! I forgot it thanks.....
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

Lokesh Duseja wrote: i did not get the last question..... overriding a class? i only heard of overriding method....

+1, there is nothing like overriding a class
Classes declared inside of interfaces are not final


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

Ankit Garg wrote:
Lokesh Duseja wrote: i did not get the last question..... overriding a class? i only heard of overriding method....

+1, there is nothing like overriding a class
Classes declared inside of interfaces are not final


I hope no one ever does that in production


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

Deepak Bala wrote:I hope no one ever does that in production

Why not, the programmer can win an Obfuscated Code Contest with it
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can a class be declared inside a interface?
 
Similar Threads
A exam sub. Can you help me?
variables in inteface
Interface method import problem
requested servlet is not available
Applet in J2EE application