首页 > 代码库 > java 内存分析之方法返回值二
java 内存分析之方法返回值二
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 内存分析之方法返回值二
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。