In the code below:
public class Square
{
private double side;
public Square(double a)
{
double side = a;
}
public double area()
{
return side * side;
}
public static void main(String[] args)
{
Square r = new Square(10.0);
System.out.println(r.area());
}
}
When the field is declared:
private double side;
and then in the constructor:
double side = a;
Why is an error not thrown?
I would think so because we are declaring the datatype of the variable double twice. Why does this code execute?