I ran over some java code and i saw something i can't quite get it .
Why does the code below work without puting this
in front of diameter
class Shape {
public double area ()
{
return 0;
}
}
class Circle extends Shape {
Circle (double diameter) {
this.diameter = diameter;
}
private static final double PI = Math.PI;
private double diameter;
public double area () {
double radius = diameter / 2.0; <-------- LOOK HERE
return PI * radius * radius;
}
}
public class Main {
public static void main(String[] args) {
Shape s1 = new Circle (2.5);
System.out.println (s1.area());
}
}
The code works perfect ... with or without this.diameter/diameter