shadowayex Posted April 13, 2011 Share Posted April 13, 2011 This may not be quite possible, but here's what I want.I have a super class that has a static property it. I want to set a different value for that property in each sub class I make, but I want he super class to still be able to use it.Example: class Foo{ protected static a; public static getA() { return self::a; }}class BarOne extends Foo{ // Set a to "One" in here somewhere}class BarTwo extends Foo{ // Set a to "Two" in here somewhere}BarOne::getA(); // Should return "One"BarTwo::getA(); // Should return "Two" I hope that explains it well enough. If not, let me know.Is that possible? Link to comment Share on other sites More sharing options...
birbal Posted April 13, 2011 Share Posted April 13, 2011 If i am not missunderstanding the question it is not possible When you inherit a static property it also been inherited in child class. static properties are class based not instance based. So the value of static properties remain same across different instance of a class. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.