How would I accomplish this?
class Test {
private int var1;
public Test(int var1) {
var1 = var1; //set the member variable to what was passed in
}
}
I'm sure there's a very obvious answer. It's just escaping me right now.
Yes, they can share the same name. However, to reference the instance variable, you need to use the this
prefix:
public Test(int var1) {
this.var1 = var1;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With