Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another Enthuware question

 
Daniel Martins
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 400
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Opinion: The public access modifier is for the object oc, nothing else! If wrong correct!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic