Well, it would compile and run. Try, for instance:
class Foo
{
double getValue;
public double getValue(double new_value)
{
getValue = 5+8;
return getValue;
}
public static void main(String args[])
{
Foo foo = new Foo();
double g = foo.getValue(5);
System.out.format("getValue is %g\n", g);
}
}
However, such a code would be
a nightmare for the poor maintainer: getValue
very name suggest a 'getter' method, that is a method returning a value without changing the state of the object. As matter of fact its body changes the state of the object.
Moreover, the passed
newValue
parameter has no effect in the method body.