en... there will be at most one "public" class in a source file. but could "protected","private" exist? it is not mentioned in SL-275 could someone be kind enough to help me? 3x
David Weitzman
Ranch Hand
Joined: Jul 27, 2001
Posts: 1365
posted
0
The best way to answer a question like this would be to write some code and try to compile it.
Mathew Kuruvilla
Ranch Hand
Joined: Nov 27, 2001
Posts: 135
posted
0
I need to know the answer to this one too. I mean, I can post code like this: b=0; --b-b--+b>>256, :-) I need to know if normal classes cannot be protected and private while this is not true for inner classes. That is inner classes can be private or protected, but not synchronized or native.
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
simeonshi, please read the Javaranch Naming Policy and register again. Thank you for your cooperation. ------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Mathew Kuruvilla
Ranch Hand
Joined: Nov 27, 2001
Posts: 135
posted
0
OK, OK. I compiled the following code successfully.
Ergo, inner classes can be private and protected. I failed to compile the following:
In each case I got the error: Test.java: <line number> modifier <modifier> not allowed here .... where modified was, depending on the class that was compiled, either private, protected, synchronized or native.
That's a lot of code that I compiled in recent days. :-)
Vinny Chun
Greenhorn
Joined: Dec 06, 2001
Posts: 24
posted
0
Please correct me if I am wrong, if I have several classes in one java file, the access modifier of the first class must be declared as public. If I leave the first class as default and declare the second class as public, I have a compiler error. class defaultClass { } public class public Class { } class OuterA { } class OuterB { } Why is that?
Simeon Shi
Ranch Hand
Joined: Dec 09, 2001
Posts: 35
posted
0
will it? i tried ur code, it compiled fine except the runtime error coz the missing 'main' method. plez attention ur 'public class publicClass' ~~~~no blank here
Mathew Kuruvilla
Ranch Hand
Joined: Nov 27, 2001
Posts: 135
posted
0
Well, the only that needs to be consistent is the NAME of the .java file and the PUBLIC CLASS in that file. You can define any number of class without being 'public' in a file having any name. If you never add a public class to that file, it will always compile. However, when you add that 'public' class, make sure that it matches the file name. The compiler looks at the name of the public class and the name of the file to determine if there is an error. I have seen a related question in the mock exam.