定义方法的问题?
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,我想问下两种方法有什么区别,是不是在那里都可以这样写?
搜索更多相关的解决方案:
定义
----------------解决方案--------------------------------------------------------
java中
public--->公共的 外部可见的 它是访问修饰符
private--->私有的 外部不可见的 同样是访问修饰符
就是说不写的话,它的访问范围就会有限制。只能在同一包中引用
----------------解决方案--------------------------------------------------------
楼上正解, 什么都不写就是默认为包访问权限
----------------解决方案--------------------------------------------------------
可以加也可以不加,顶楼上的!
----------------解决方案--------------------------------------------------------