If you inherit from an activity where certain member variables were declared, how do you access these member variables in the subclass executing the inheritance?
class A {
protected int a = 3;
}
class B extends A {
protected int b = 2;
void doIt() {
System.out.println("super.a:" + super.a);
System.out.println("this.b: " + this.b);
}
}
public
or protected
member names can be accessed via this.memberName
from any constructor or non-static
method or initializer.
private
or package level members (accessed from a subclass in a different package) cannot be accessed directly and will need to be accessed via an unprivileged interface such as a public
getter.
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