• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

class inside interace

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can we have a class inside an interface. Please explain with reasons.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good point..I never used such scenario anytime.. but you can have a look at this.
http://www.sap-img.com/java/why-we-define-a-class-inside-an-interface.htm
If I find anything more better i l post it
 
nimish kumar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Siddhesh Deodhar wrote:Good point..I never used such scenario anytime.. but you can have a look at this.
http://www.sap-img.com/java/why-we-define-a-class-inside-an-interface.htm
If I find anything more better i l post it



Thanks Sid for the link..Please post if anything more you get on this..
 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Having interface-like declarations within a class is common;
it makes the class abstract, but the other way round is at odds
with the interface concept. Interfaces declare signatures but
are not allowed to include implemented behaviors.

Why does this question come up?
 
nimish kumar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jim Hoglund wrote:Having interface-like declarations within a class is common;
it makes the class abstract, but the other way round is at odds
with the interface concept. Interfaces declare signatures but
are not allowed to include implemented behaviors.

Why does this question come up?



@Jim I was asked in an interview..... I was totally blank..
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as innerclasses are concerned , a class can be declared inside an interface when compared with normal regular classes.


To create an object of this inner class use



I think you can get an idea by looking at this example
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep in mind that in interfaces, like fields, nested classes are implicitly public and static.
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


OUTPUT:

Thanks Rob. It's interesting that both the instantiated
and static calls work. However, the static method does
not like the "this" reference.
Jim...
 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic