Simple question. I made a class called Tester1 which extends another called Tester2. Tester2 contains a public string called ‘ABC’.
Here is Tester1:
public class Tester1 extends Tester2
{
public Tester1()
{
ABC = "Hello";
}
}
If I instead change line 5 to
super.ABC = "Hello";
am I still doing the exact same thing?
Yes. There’s only one ABC variable within your object. But please don’t make fields public in the first place. Fields should pretty much always be private.
If you declared a variable
ABCwithinTester1as well, then there’d be a difference – the field inTester1would hide the field inTester2, but usingsuperyou’d still be referring to the field withinTester2. But don’t do that, either – hiding variables is a really quick way to make code unmaintainable.Sample code: