Any of the following solutions will work:
- Remove the keyword,
public
from the definition of the classes,Circle
andSquare
- Write the classes,
Circle
andSquare
as they are (i.e. withpublic
keyword) 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