If I have 2 classes and the first extends the second, how can the second class call a static function from the first?
package p1 {
class a {
static function a1() {
//do soemthing
}
}
class b extends a {
static function b1() {
//do something else
}
}
}
a.a1(); // this works
b.a1(); // this doesn't work
b.b1(); //this works
When "B extends A" - this actually is not the same as "class B has all methods and properties of A". Not class, but object of class B implements all properties and methods, defined in class A. When you call a static method or property - you deal with classes but not objects (it looks very similar to namespaces usage).
ADDED: The only way solve your task is to override a1(args) in class B and to call super.a1(args) inside... 1 string of code. But it seems to me, that you have a software architect problem if it's not possible to avoid such kind of usage.
Use super to call the parent method.
super.b1();
EDIT: Ok, looking at what you wrote, I think you need to set the scope of a1 to be public or protected.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.