public class swap
{
public class Point
{
public int x=0;
public int y=0;
public Point(int a, int b)
{
this.x = a;
this.y = b;
}
public void swapxy(Point p)
{
int t;
t = p.x;
p.x = p.y;
p.y = t;
}
public String ToString()
{
return ("x="+x+" y="+y);
}
}
public static void main(String[] args)
{
Point pxy = Point(10,20);
pxy.swapxy(pxy);
System.out.println(pxy);
}
}
我得到的方法是undefined錯誤Point pxy = Point(10,20);
什麼是錯的?使用構造函數智能在Java中的新對象
請重新格式化您的代碼。把它複製到一個編輯器中按TAB鍵縮進一次,並將代碼複製回問題中。 –
你有任何C背景嗎? –