关于下面3段代码我有几个地方,不知道理解的对不对,请打开下面的地址,我做了张图片格式,来模拟机器在内存中做的工作。
http://p.blog.csdn.net/images/p_blog_csdn_net/llm0528/403746/o_001.jpg第一段
import static java.lang.Math.sqrt;
class Point {
double x;
double y;Point(double xVal,double yVal){
x = xVal;
y = yVal;
}
Point(final Point oldPoint){
x = oldPoint.x;
y = oldPoint.y;
}
void move(double xDelta,double yDelta){
x += xDelta;
y += yDelta;
}
double distance(final Point aPoint){
return sqrt((x - aPoint.x)*(x - aPoint.x) + (y - aPoint.y)*(y - aPoint.y));  
}
public String toString(){
return Double.toString(x) + ", " + y;
}
}
第二段
class Line{
Point start;
Point end;Line(final Point start, final Point end){
this.start = new Point(start);
this.end = new Point(end);
}
Line(double xStart, double yStart, double xEnd, double yEnd){
start = new Point(xStart, yStart);  
end =  new Point(xEnd, yEnd);
}double length(){
return start.distance(end);  
}
public String toString(){
return"(" + start + "):(" + end + ")";
}
//后面是计算公式
Point intersects(final Line line1){
Point localPoint = new Point(0,0);double num = (this.end.y - this.start.y)*(this.start.x - line1.start.x)-
            (this.end.x - this.start.x)*(this.start.y - line1.start.y);double denom = (this.end.y - this.start.y)*(line1.end.x - line1.start.x)-
              (this.end.x - this.start.x)*(line1.end.y - line1.start.y);  localPoint.x = line1.start.x + (line1.end.x - line1.start.x)*num/denom;
  localPoint.y = line1.start.y + (line1.end.y - line1.start.y)*num/denom;  return localPoint;
}
}
第三段
public class TryGeometry{
public static void main(String[] args){
Point start = new Point(0.0 , 1.0);
Point end = new Point(5.0 , 6.0);
System.out.println("Points created are "+ start + " and " + end);Line line1 = new Line(start, end);
Line line2 = new Line(0.0, 3.0, 3.0, 0.0);
System.out.println("Lines created are " + line1 + " and " + line2);System.out.println("Intersection is " + line2.intersects(line1));end.move(1.0, -5.0);
System.out.println("Intersection is " + line1.intersects(line2));
}

解决方案 »

  1.   

    没看见什么图      也没有仔细看代码  
      不过 我知道  当我们new一个对象的时候  是在 栈内存里有一小块内存(引用)  可以指向  new出来的  堆内存中的东西。建议看    马士兵  的视频   里面对内存的分配有详细的讲解 
      我也是前2天才刚看完的
      

  2.   

    http://p.blog.csdn.net/images/p_blog_csdn_net/llm0528/403746/o_001.jpg 
    这个地址里没图??我怎么打开来有的??