码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-06-13 23:56:33      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:one   string   ati   stat   技术   nbsp   返回   package   方法   

技术分享
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 内存分析之方法返回值二

标签:one   string   ati   stat   技术   nbsp   返回   package   方法   

原文地址:http://www.cnblogs.com/BaiLaowu/p/7003951.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!