Dart code:
main() {
print(PPP.name);
print(CCC.name);
}
class PPP {
static String name = "PPP";
}
class CCC extends PPP {
}
It prints:
PPP
Unhandled exception:
No static getter 'name' declared in class 'CCC'.
NoSuchMethodError : method not found: 'name'
Receiver: Type: class 'CCC'
Arguments: [...]
So it's not available to visit static variables of parent class in Dart?
From Dart Programming Language Specification:
The static members
of a class are its static methods
, getters
, setters
and static variables
.
Superclass static members
are not in scope in subclasses
, and do not conflict
with subclass members
.never inherited
.never override anything
.So if you declare some static members in superclass then these members are not inherited in subclasses.
They remain in that class where they declared and do not conflicts with other declarations static members in the subclasses.
Q: Can't visit static variable of parent class in Dart?
A: Static variable of parent class cannot be accessed (as its own) in child class because it does not exists (not inherited) in child class.
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