Java identifier expected
A little confused. I have such constructors:
public Circle() {
this.center = new Point(0,0);//center.getX()
this.inline = new Point(10,0);//inline.getX()
}
public Circle(Point center, Point inline) {
this.center = center;
this.inline = inline;
}
And I want to do the following:
List<IShape> shapes=new ArrayList();
shapes.add(new Circle(new Point(0,0),new Point(5,5) ));
shapes.add(new Circle());
Circle implements IShape. But when you add a shape, the development environment says the following:
Expected
Illegal start of type
Package shapes does not exist
How to solve this problem?
P.S. I'm adding the entire file.
package shapesprog;
import java.util.ArrayList;
import java.util.List;
public class ShapesDAO {
List<IShape> shapes = new ArrayList();
shapes.add(new Circle(new Point(0,0),new Point(5,5) ));
shapes.add(new Circle());
shapes.add();
}
0
Author: Мария Линк, 2020-10-31
2 answers
public class ShapesDAO {
List<IShape> shapes = new ArrayList();
public ShapesDAO() {
shapes.add(new Circle(new Point(0,0),new Point(5,5) ));
shapes.add(new Circle());
shapes.add();
}
}
1
Author: Igor, 2020-10-31 14:57:28
Thank you, I decided. Added all the code inside the class to the static block.
0
Author: Мария Линк, 2020-10-31 14:23:49