Forums Register Login

Another Enthuware question

+Pie Number of slices to send: Send


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.
+Pie Number of slices to send: Send
 

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...
+Pie Number of slices to send: Send
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...
+Pie Number of slices to send: Send
I got confused with the public OtherClass oc = new OtherClass();

I do not remember seing something like this: public A a = new A();
+Pie Number of slices to send: Send
That's an instance field of the class, it can be declared public, protected, private or default scope i.e. package visible...
+Pie Number of slices to send: Send
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


reply
reply
This thread has been viewed 806 times.
Similar Threads
Problem with Exceptions
Unable to run pgm. when in jar....
Is there away I can have two or more classes in same file?
GUI classes, implementing ActionListener.
Packages etc.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:00:35.