问题遇到的现象和发生背景
problem1:为什么把构造方法写在class 里面的时候下面没办法用new Circle
我把构造方法写在外面的时候就可以了呢
problem2:建类的时候为什么要在z1前面加w1 变成w1.z1呢 我单纯用z1的时候发现不行
package w1.z1;
import java.util.Scanner;
class Point{
double x;
double y;
public Point(double x,double y) {
this.x = x;
this.y = y;
}
public String toString() {
return"("+x+","+y+")";
}
}
class Circle{
double x;
double y;
double r;
public Circle() {
this.x = 0;
this.y = 0;
this.r = 0;
}
public Circle(double x,double y,double r) {
this.x = x;
this.y = y;
this.r = r;
}
public Circle(Point p,double r) {
this.x = p.x;
this.y = p.y;
this.r = r;
}
public String toString() {
return"("+"("+x+","+y+")"+","+r+")";
}
}
public class z1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Scanner sc = new Scanner(System.in);
System.out.println(new Circle());
Circle c = new Circle(1,1,3);
System.out.println(c);
Point p = new Point(3,4);
System.out.println(new Circle(p,5));
}
}