Answer the question
In order to leave comments, you need to log in
How to refer to an object from another class?
There is a class Circle
public class Circle extends Shape {
private double radius;
public Circle(String shapeColor, double radius) {
super(shapeColor);
this.radius = radius;
}
public double calcArea() {
return Math.PI * Math.pow(radius, 2);
}
@Override
public String toString() {
return "This is Circle, color: " + shapeColor + ", radius =" + radius + "\nShape area is: " + calcArea();
}
public static void main(String[] args) {
Circle kub = new Circle("GREEN", 10);
System.out.println(kub);
}
}
Answer the question
In order to leave comments, you need to log in
Good afternoon.
The kub object is located in the scope of the main method. This object cannot be accessed from another class.
How can I access this object from another class?
pseudocode
class Circle extends Shape {}
class Triangle extends Shape {}
public class Main { void main() }
class Circle extends Shape { void main() }
class Triangle extends Shape { void main() }
т.е. каждый pojo класс должен содержать точку входа, что странно...
И еще один совет, осознанно давайте названия переменным, классам, методам.
А то <code>Circle kub</code> (Круг квадрат) ну сами понимаете.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question