How do I use instance variables twice without renaming them?
•
Java
Help, I've just started learning Java. This online tutorial I'm doing requires me to create an instance of a class The instance should be created first as a "Rectangle" object and then as a "circle" object But eclipse asked me to rename the second "drawobject"
public class TestPolymorph {
public static void main(String[] args) {
Shape drawObject = new Rectangle(40,60);
drawObject.draw();
Shape drawObject = new Circle(40);
drawObject.draw();
}
}
Solution
If you recall the shape again, it will be an appropriate repair
The editor gave him a better solution
public class TestPolymorph {
public static void main(String[] args) {
Shape drawObject = new Rectangle(40,60);
drawObject.draw();
drawObject = new Circle(40);
drawObject.draw();
}
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
