Hi
we want to make separate class which contain a static method and it class inherit in a child class and use its static method is it possible or not if possible then proved by example.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SenthilkumarPosted Apr 5, 2012, 8:13 PM
Yes! you are right!! I didn't see the section. Usually the .net developers asks more questions in this forum.
Since i am new new contributor to the forum, not aware the such things.
let me see the section before answering the questions..... But the java/C# concept wise almost same... but the question was also not clear. he wants to call the parent static method from the inherited child class method or if static method in the parent class is accessible when another child class inherits...
Sam HobbsPosted Apr 5, 2012, 5:30 PM
VulpesPosted Apr 5, 2012, 5:51 AM
If you're asking whether a derived class inherits its parent's static methods, the answer is that it does and can access them as long as they're not private.
The following program prints Hello World twice:
SenthilkumarPosted Apr 5, 2012, 12:00 AM
It is typical object oriented technique to work around. But i am not sure.
I though we can't do that. But when your child class have the static method and want to try in differently it may be possible.
I suggest you to work out this.
Another way:
same thread on another forum:
http://stackoverflow.com/questions/603177/c-how-do-i-call-a-static-method-of-a-base-class-from-a-static-method-of-a-deri
Jignesh TrivediPosted Apr 4, 2012, 11:22 PM
It is not possible.
but you can create simple method instead of static method.
Example:
public class test
{
public int id { get; set; }
public string name { get; set; }
public string GetName()
{
return "my name";
}
}
class test1 : test
{
public bool IsId { get; set; }
public string name { get; set; }
public string MyName()
{
return base.GetName();
}
}
hope this help.