定义方法的问题?
class Point {double x;
double y;
double z;
public Point (double _x, double _y, double _z) {
x = _x;
y = _y;
z = _z;
}
public void reworkX(double i) {
x = i;
}
……
}
public class kongjiandian {
public static void main(String args[]) {
Point s = new Point(3.2,2.4,3.5);
Point y = new Point(0.0,0.0,0.0);
System.out.println(s.distance(y));
}
}
===============================
class Point {
double x;
double y;
double z;
Point (double _x, double _y, double _z) {
x = _x;
y = _y;
z = _z;
}
void reworkX(double i) {
x = i;
}
……
}
public class kongjiandian {
public static void main(String args[]) {
Point s = new Point(3.2,2.4,3.5);
Point y = new Point(0.0,0.0,0.0);
System.out.println(s.distance(y));
}
}
===================================
上面两种定义方法中第一种有public,而第二种没有public,我想问下两种方法有什么区别,是不是在那里都可以这样写?