• 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

inner class

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I tried to compile this code with jdk1.4 and got compile time error. I am not getting the cause for this error.
But when I compile this code with jdk1.3 on Windows98 I get some exceptions. I haven't experienced this type of exception. Please try to help me out.
Regards
-Manish
[ fixed UBB code tags ]
[ May 01, 2002: Message edited by: Jessica Sant ]
 
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you tell the exceptions you are getting on JDK1.3..
AW inner classes can access private members of enclosing class but outer class can not access private members of inner class.
CMIW
HTH
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Manish Kumar:


I also got error with JDK1.3

In your println() I am not sure if it is correct to access the inner class by the class name as the class itself is not static? I think you must access the inner class by its instance name. If you change the println() as follows everything compiles and runs correctly.

Can anyone else explain better why the original code doesn't work?
HTH
Alex
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a field access expression it's possible to have:
TopLevelClass.NestedClass.field
like
System.out.println(Q.Question25Inner.i);
but it isn't possible:
variableOfTopLevelClass.NestedClass.field
like
System.out.println(q[0].Question25Inner.i);
or
System.out.println(new Q().Question25Inner.i);
the compiler error is helpful:
"
Q.java:15: unexpected type
required: class, package
found : value
"
also possible:
variableOfTopLevelClass.variableOfNestedClass.field
like
System.out.println(q[0].inner.i);
[ May 01, 2002: Message edited by: Jose Botella ]
 
R K Singh
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
opsssss...
first ... why the hell I did not notice class name instead of var name.....
second .. thanks Jose and all for correcting me..
Outer class can access private members of Inner class.
repeating it 10 times ...
Thanks a lot
 
Manish Kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But Jose compile the following code with jdk1.3

This code compiles and runs without any problem with JDK1.3. But JDK1.4 gives compilation error. Is there anything about the "field access expression" in JLS ?
What should I do if I get a expression like

in the exam?
Thanks and regards
-Manish
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic