Main class:
public class Main { public static void main(String[] args){ Circle c = new Circle(); } } The abstract class Shape, from which I inherit
abstract class Shape { double area; Shape(){ calculateArea(); } protected abstract void calculateArea(); } The class that catches the problem
class Circle extends Shape{ float radius = 10f; Circle() { super(); } @Override protected void calculateArea() { area = 2 * Math.PI * this.radius; System.out.println(radius == 0); System.out.println(radius + "rad in calc"); System.out.println(area + " = area"); } } When starting it displays this. true 0.0rad in calc 0.0 = area
I do not understand why the variable radius is zero. Indeed, in the Shape class, I initialize it (radius = 10f)