当前位置: 技术问答>java相关
小菜向各位大哥请教一个弱问题!!
来源: 互联网 发布时间:2015-08-31
本文导语: import java.awt.*; import java.applet.*; class PointTest{ public static void main(String[] args){ MyPoint mp=new MyPoint(4,3); Point q=mp; mp.x=5; mp.y=12; System.out.println("q=("+q.x+","+q.y+")"); System.out.println("q.length()="+q.length()); } } class Poi...
import java.awt.*;
import java.applet.*;
class PointTest{
public static void main(String[] args){
MyPoint mp=new MyPoint(4,3);
Point q=mp;
mp.x=5;
mp.y=12;
System.out.println("q=("+q.x+","+q.y+")");
System.out.println("q.length()="+q.length());
}
}
class Point{
int x;
int y;
Point(int x,int y){
this.x=x;
this.y=y;
}
Point(int x){
this (x,0);
}
Point(){
this(0,0);
}
double length(){
return Math.sqrt(x*x+y*y);
}
}
class MyPoint extends Point{
int x;
int y;
MyPoint(int x,int y){
this.x=super.x=x;
this.y=super.y=y;
}
double length(){
return Math.sqrt(x*x+y*y);
}
double distance(){
return Math.abs(length()-super.length());
}
}
为何去q.x=4,q.y=5而q.length=13!!
import java.applet.*;
class PointTest{
public static void main(String[] args){
MyPoint mp=new MyPoint(4,3);
Point q=mp;
mp.x=5;
mp.y=12;
System.out.println("q=("+q.x+","+q.y+")");
System.out.println("q.length()="+q.length());
}
}
class Point{
int x;
int y;
Point(int x,int y){
this.x=x;
this.y=y;
}
Point(int x){
this (x,0);
}
Point(){
this(0,0);
}
double length(){
return Math.sqrt(x*x+y*y);
}
}
class MyPoint extends Point{
int x;
int y;
MyPoint(int x,int y){
this.x=super.x=x;
this.y=super.y=y;
}
double length(){
return Math.sqrt(x*x+y*y);
}
double distance(){
return Math.abs(length()-super.length());
}
}
为何去q.x=4,q.y=5而q.length=13!!
|
q.length 是调用的是MYPoint.length()