[Java Review] 4: Ram analysis

The following notes are based on video series: 手把手教你用Java基础教程 - 北京尚学堂 - 马士兵

Step by step ram analysis

blog ram analysis

Corresponding Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class Point {
double x;
double y;
double z;

Point(double _x, double _y, double _z){
x = _x;
y = _y;
z = _z;
}

public void setX(double _x){
x = _x;
}

public void setY(double _y){
y = _y;
}

public void setZ(double _z){
z = _z;
}

public double getDistance(Point p){
return Math.pow(x-p.x,2) + Math.pow(y-p.y,2) + Math.pow(y-p.y,2);
}

}

class TestPoint{

public static void main(String[] args) {
double a = 1.0, b = 2.0, c = 3.0;
Point p1 = new Point(a, b, c);
p1.setX(4);
System.out.println(p1.getDistance(new Point(3,2,1)));
}
}
0%