Steve Bret

Greenhorn
+ Follow
since May 03, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Steve Bret

This should do what you want:

try to follow the rules when naming variables/objects
variables should start with a small characters
So Receive_Message --> receiveMessage
...

14 years ago
For info I get this error message:
C:\Java\test>javac -classpath C:\jdk1.5\bin TopLevelA.java
TopLevelA.java:14: <identifier> expected
zz2 = z;
^
1 error
14 years ago
Why can't I say :
zz2 = z;
after the line
double zz2 = z;
??

thanks

Below the code.
14 years ago
The compiler to find out the value of EARTH is first searching through its nearest variables in this case it is first searching in Planet, where it can
find the EARTH.

Apparently it is not bothered if another EARTH is existing.

When those are declared in 2 different files (in same directory) the specification of which EARTH is required.

thanks for your anwswer.
14 years ago
I do not understand you answer.
I did what you said and I can compile without problem. See below.

The question I have is still:
what is the logic for the compiler to pick up
Planet.EARTH over XPlanet.EARTH when I declare only EARTH (in the code above)?
I have 2 EARTH to choose from and they are different.
1- Why did the compiler select Planet.EARTH over XPlanet.EARTH?
2- Why is it not confused : (both enums are public)?

public enum Planet {EARTH(1.00e+1, 1.0e1), MERCURY(2.2e+22, 2.2e2);
private final double mass;
private final double radius;

Planet(double mass, double radius) {
this.mass = mass; this.radius = radius;
}
public double mass() {return mass;}
public double radius() {return radius;}

//public enum XPlanet {EARTH(3.0e+3), XVENUS(4.0e+4);
//private final double mass;
//XPlanet(double mass) {this.mass = mass;}
//public double mass() {return mass;}
//}
public static void main(String[] args) {
System.out.println("mass = " + EARTH.mass()); // 10.0
//System.out.println("mass = " + XPlanet.EARTH.mass()); // 3000.0
}
}
14 years ago
I cannot understand how the EARH has been selected in the first output of the main.
I have 2 earth but by the first one is selected even if 2 are available.
What is the rule for the selection of a variable?

public enum Planet {EARTH(1.00e+1, 1.0e1), MERCURY(2.2e+22, 2.2e2);
private final double mass;
private final double radius;

Planet(double mass, double radius) {
this.mass = mass; this.radius = radius;
}
public double mass() {return mass;}
public double radius() {return radius;}

public enum XPlanet {EARTH(3.0e+3), XVENUS(4.0e+4);
private final double mass;
XPlanet(double mass) {this.mass = mass;}
public double mass() {return mass;}
}
public static void main(String[] args) {
System.out.println("mass = " + EARTH.mass()); // result: 10.0 (from Planet)
System.out.println("mass = " + XPlanet.EARTH.mass()); // result: 3000.0 (from XPlanet)
}
}
14 years ago