This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Another Enthuware question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Another Enthuware question" Watch "Another Enthuware question" New topic
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
Sheriff

Joined: Aug 03, 2008
Posts: 9307
    
  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...


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
Sheriff

Joined: Aug 03, 2008
Posts: 9307
    
  17

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%|
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Another Enthuware question