| Author |
Another Enthuware question
|
Daniel Martins
Ranch Hand
Joined: Oct 22, 2009
Posts: 45
|
|
Is this legal: public OtherClass oc = new OtherClass(); ?
I has the answer rigth (The class will fail to compile)because I assumed the previous line was not legal...however that was not the cause.
|
 |
Minhaj Mehmood
Ranch Hand
Joined: Jan 22, 2007
Posts: 400
|
|
Daniel Martins wrote:
Is this legal: public OtherClass oc = new OtherClass(); ?
I has the answer rigth (The class will fail to compile)because I assumed the previous line was not legal...however that was not the cause.
The package declaration statement must be the first line of code in class...
|
SCJP6 96% | SCWCD5 81% | SCDJWS5 79%
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9191
|
|
|
Daniel, the order of declaration of classes don't matter, you can declare references of a class even if they are declared after they are used. As far as I remember, in C++ you had to declare a class before it was used, but its not the case in java, so if you got confused because of that, then don't be...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Daniel Martins
Ranch Hand
Joined: Oct 22, 2009
Posts: 45
|
|
I got confused with the public OtherClass oc = new OtherClass();
I do not remember seing something like this: public A a = new A();
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9191
|
|
|
That's an instance field of the class, it can be declared public, protected, private or default scope i.e. package visible...
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
|
My Opinion: The public access modifier is for the object oc, nothing else! If wrong correct!
|
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
|
 |
 |
|
|
subject: Another Enthuware question
|
|
|