Reputation: 11
Hi all I just wanted to know whether a static class which inherits another class, can have access to the parent classe's non static members or not? Please help. Thanks in advance.
Upvotes: 1
Views: 123
Reputation: 56537
A static class can't inherit from any classes or implement any interfaces.
A static class does implicitly inherit from Object
, though. But since it's (also implicitly) abstract you can never have any instances of it, and so can never call any instance methods in Object
. Also, it's (implicitly) sealed, and as such cannot have subclasses that would be instantiatable. As a corollary to these characteristics, it can't be used to type any variables, fields or parameters; and it can't be used as a type parameter (if these were possible, null
would be the only valid value for such references).
Given all this, a static class does not look like a class at all, and I think would be better represented as a module.
Upvotes: 0
Reputation: 11387
static class
cannot inherited .
I think you can go with the same concept with SingleTon
class and you can inherit the same.
Upvotes: 0
Reputation: 46425
A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. In other words, you cannot use the new keyword to create a variable of the class type
You can view more information about static classes.
Upvotes: 0
Reputation: 15722
How should that work? A static class cannot be instantiated and therefor it will never have access to any non static members.
Upvotes: 0
Reputation: 888203
A static
class cannot inherit or implement any class or interface.
The point of inheriting or implementing a class or interface is to allow instances of your class to be used as the base type.
Since static classes cannot have instances, there's no point.
Upvotes: 3