• 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

regarding inner classes

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

in java quick reference i have read one sentence "you cannot declare an interface as a member of an inner class; interfaces are never inner ".

But the foll code is compiled successfully.why?

public class TestFields {
interface NeverInner{}
public static void main(String args[]) {
}
}

I need a clarificatoin on this please...
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It said you cannot have an interface as a part of an inner class. What you have is an interface as part of a top-level class.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ashok ch:


in java quick reference i have read one sentence "you cannot declare an interface as a member of an inner class; interfaces are never inner ".


a static nested class is implicitly or explicitly static
but an inner class is not implicitly or explicitly static
the member interface is implicitly static
so ....
 
ashok ch
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry,I have not read the statement properly.

Thanks a lot
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more point,Changchun !

Can i say that all the members of static inner class are becomes auto. static.

Regards,
Sachin!!!
 
Changchun Wang
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Sachin Dimble

only member interface is implicitly static
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No the members of a static nested class are not implicitly static.
 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If that is the case, have a look at below code..

class Outer
{
int i=12;
static int i1=10;
static class iner
{
void method()
{
// S.o.p(i);
S.o.p(i1);

}
}
}

at commented line it will throw error non-static member can not referenced from static context(is that mean method() is static,Implicitly static!!!).

Regards,
Sachin!!!
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is in a static context because the nested class is static.
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out this example. If the method in the first nested class were implicitly static, then it would be hidden by the subclass and not overridden.

 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Keith! I got the point.

Sachin!!!
 
Changchun Wang
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sachin Dimble
I misunderstand your meaning ,that is my fault.


Can i say that all the members of static inner class are becomes auto. static


answer:no
a static nested class is just a top-level class
inside it,the field or mehtod if are static or not completly depend on the modifies you declaring.


review what I am thinking
inside class ,before long I thought only interface member is implicitly static ,but now there also exists one member,
it is enum type(using jdk5.0).


inside interface , all the class(besides abstract class) and interface are implicitly static.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic