aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner class code,confusing 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 "Inner class code,confusing" Watch "Inner class code,confusing" New topic
Author

Inner class code,confusing

WiLL Tao
Ranch Hand

Joined: Dec 14, 2001
Posts: 56
This code about static inner class access private
variable.please tell me reason in my comment,Thanks


Thank Folks who <b>Make Sense</b> here.<br />SCJP Platform 2
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
This isn't really a question about inner classes. Also, please note this is NOT an inner class anyway, it's a nested top-level class. Static classes can't be inner classes.
But your problem is that you're trying to include a statement in a location where it isn't allowed. A nested class obeys the same rules as a top level class. You can't just throw a println() statement anywhere you want, it has to be inside a method or a constructor.
For example, you can't do this :
class Foo{
System.out.println(); //compiler error
}
The only things allowed outside of a method or a constructor are variable declarations with or without an initializer, and static or instance inizitializers, as you have used in your code.
To fix the above class, you either delete the println() or put it in a method:


Rob
SCJP 1.4
WiLL Tao
Ranch Hand

Joined: Dec 14, 2001
Posts: 56
Thanks Rob
You correct me,now i am clear.
[ March 31, 2002: Message edited by: WiLL Tao ]
 
Consider Paul's rocket mass heater.
 
subject: Inner class code,confusing