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背景吗? –