package Demo;

class Point {
private double x, y; public Point(double x, double y) {
this.x = x;
this.y = y;
} public double getX() {
return x;
} public void setX(double x) {
this.x = x;
} public double getY() {
return y;
} public void setY(double y) {
this.y = y;
}
} class Circle {
private Point o;
private double radius; Circle(Point p, double r) {
o = p;
radius = r;
} Circle(double r) {
o = new Point(0.0, 0.0);
radius = r;
} boolean contains(Point p) {
double subtractX = p.getX() - o.getX();
double subtractY = p.getY() - o.getY();
double distance = (subtractX * subtractX) + (subtractY * subtractY);
return distance < radius ? true : false;
} public double area() {
return 3.14 * radius * radius;
} public Point getO() {
return o;
} public void setO(Point o) {
this.o = o;
} public double getRadius() {
return radius;
} public void setRadius(double radius) {
this.radius = radius;
} } public class TestCircle {
public static void main(String[] args) {
Circle c1 = new Circle(new Point(1.0, 2.0), 2.0);
Circle c2 = new Circle(5.0);
System.out.println("c1:(" + c1.getO().getX() + "," + c1.getO().getY() + "(," + c1.getRadius());
}
}

源码

内存分析:

java 内存分析之方法返回值二-LMLPHP

05-06 02:38