有关java对象引用的问题

wzwuq 2007-11-29 09:23:26
求教一下代码错误提示地解决方法:
错误提示:
non-static variable this cannot be referenced from a static context at line 14 (14:14)
class lesson42 {
class point{
int x,y;

point(int x,int y){

this.x=x;
this.y=y;

}
}
public static void main(String[] args) {
point p = new point(1,1);
point[] pt1 ;//=new point[]{ new point(1,1),new point(2,2),new point(3,3)};
}
}
...全文
89 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
p0303230 2007-11-29
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20071129/09/8d21157d-216c-4dc4-b810-0e051b4a8228.html
Johnson_Hong 2007-11-29
  • 打赏
  • 举报
回复
point 是 lesson42的一个属性,你这样写就对了
class lesson42 {
class point {
int x, y;

point(int x, int y) {

this.x = x;
this.y = y;

}
}

public static void main(String[] args) {
lesson42 l = new lesson42();
point p = l.new point(1, 1);
point[] pt1;// =new point[]{ new point(1,1),new point(2,2),new
// point(3,3)};
}
}
gwu0318 2007-11-29
  • 打赏
  • 举报
回复
如果想从外部类的非静态方法之外的任意位置创建某个内部类的对象,就必须具体地指明这个对象的类型:OutClassName.InnerClassName
这里应该这样写:lesson42.point p = new lesson42().new point(1, 1);
gwu0318 2007-11-29
  • 打赏
  • 举报
回复
如果想从外部类的非静态方法之外的任意位置创建某个内部类的对象,就必须具体地指明这个对象的类型:OutClassName.InnerClassName
这里应该这样写:lesson42.point p = new lesson42().new point(1, 1);

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧