Any of the following solutions will work:
- Remove the keyword,
publicfrom the definition of the classes,CircleandSquare - Write the classes,
CircleandSquareas they are (i.e. withpublickeyword) in separate files.
The reason is that Java supports only one public class in a source file.
A couple of more points:
A. You should instantiate Circle and Square as follows:
Shape circle = new Circle(true, 10);
Shape square = new Square(true, 10);
B. As per your assignment (in the picture), you are supposed to use boolean but you have used Boolean. Note that it doesn’t have anything to do with the compilation errors.
1
solved Implementation OOP in JAVA