Daniel Martins
,
Ranch Hand
Feb 11, 2010 12:14:46
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
Feb 11, 2010 12:23:34
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...
Ankit Garg
,
Sheriff
staff
Feb 11, 2010 12:38:17
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...
Daniel Martins
,
Ranch Hand
Feb 11, 2010 12:52:15
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
,
Sheriff
staff
Feb 11, 2010 14:14:22
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
Feb 12, 2010 09:08:57
My Opinion: The public access modifier is for the object oc , nothing else! If wrong correct!
To do a great right, do a little wrong - shakepeare. twisted little ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com