Right now I am trying to instantiate the Circle class (which is a subclass of Shape) in a method in my menu class. But the problem is that I keep getting a compiler error say Circle cannot be resolved to a type. In other words in does not even recognize my Circle class as an instance, it just thinks it’s another variable. I’ve tried using variables in the instantiation and I have tried using setters in the constructor.
Here is the method in the menu class where I am trying to instantiate Circle
public void select_case()
{
switch (menu_select)
{
case 1: Circle c = new Circle(1);
break;
}
}
Just in case you need to know, menu_select is a private integer variable.
Here is the code for my Circle class. I am only going to show the constructors to make less clutter.
public class Circle extends Shape
{
final private pi = Java.lang.Math.PI;
//Constructor
Circle(double r)
{
super(r);
}
}
And here is the code for the shape superclass. Like the code for the circle class only the constructors are shown.
public abstract class Shape
{
private static double scaleFactor;
private double base;
private double radius;
private double height;
//Constructor for circle
public Shape(double r)
{
radius = r;
}
//Constructor for rectangle
public Shape(double b, double h)
{
base = b;
height = h;
}
}
should be
or just
I don’t see any errors in the code other than this.