求教一下代码错误提示地解决方法:
错误提示:
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)};
}
}
错误提示:
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)};
}
}
public class Lession42 {
class Point{
int x,y; Point(int x,int y){ this.x=x;
this.y=y; }
}
public static void main(String[] args) {
Lession42 lession=new Lession42();
Lession42.Point p=lession.new Point(1,1);
}
}
Lession42 lession=new Lession42();
Lession42.Point p=lession.new Point(1,1);
也可以:
Lession42.Point p= new Lession42().new Point(1,1);
要有一个PUBLIC类
{
static 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);
}
}
不想加PUBLIC 这样也可以!