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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 4, 2012, 7:22 PM EDT
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.
SenthilkumarRank #387 · 6.5K reputationPosted Apr 4, 2012, 8:00 PM EDT
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
VulpesRank #55 · 29.2K reputationPosted Apr 5, 2012, 1:51 AM EDT
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:
Sam HobbsRank #107 · 20.5K reputationPosted Apr 5, 2012, 1:30 PM EDT
SenthilkumarRank #387 · 6.5K reputationPosted Apr 5, 2012, 4:13 PM EDT
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...