The class variable is the one defined by the class as a static
field, and the parameter is the one defined by the method. It's just that simple. There are also instance variables (defined at the class level but not static) and local variables (defined within a method, but not as input parameters).
public class Foo {
private static String someName; // this is a class variable
private String someOtherName; // this is an instance variable
public Foo(String anotherName) { // anotherName is a constructor parameter
int yetAnother = 1; // yetAnother is a local variable
someOtherName = "foo"; // assign a value to someOtherName
}
These two variables are completely distinct. They don't even have to have the same type! The only complication in your example is that both variables happen to have the same name. When that happens, the compiler will favor the constructor parameter (or method parameter, or local variable) over the class variable. In order to "force" it to use the class variable, you prefix it with this.
.
The thing to keep in mind is that the two variables are totally separate, regardless of their names.
So this:
class NewClass {
private String Variable = "";
Public NewClass (String Variable)
{
NewClass.Variable = Variable;
}
}
is exactly the same as this:
class NewClass {
private String Variable = "";
Public NewClass (String someOtherVariableName)
{
NewClass.Variable = someOtherVariableName;
}
}
... and it's also exactly the same as this:
class NewClass {
private String Variable = "";
Public NewClass (String Var)
{
NewClass.Variable = Var;
}
}
The convention of using the same name for a parameter as for the class variable just means you don't have to come up with pointless variants on the variable name.