I'm new to Java. There's a question on the my recent Java test which I don't really understand, and hope that you guys will help me with it.
Analyze the following code:
class Circle {
private double radius;
public Circle(double radius) {
radius = radius;
}
}
Here are the answers:
A) The program will compile, but you cannot create an object of Circle with a specified radius. The object will always have radius 0.
B) The program has a compilation error because you cannot assign radius to radius.
C) The program has a compilation error because it does not have a main method.
D) The program does not compile because Circle does not have a default constructor.
In my opinion, I think A is correct. B is clearly wrong because you can of course do the assignment. C is wrong because not having the main method is completely fine. D is also wrong because default constructor is not necessary. This left me with A.
I don't understand the wording of A. I think this code can be changed to:
this.radius = radius;
to be correct.
Can anyone help me clarify this? Thank you a lot!