Interviews3 answers
How can we call the base class method without creating an instance?
3 Answers
For Static Methods ,You can call a base class method without creating an instance of the class by using static methods
Example :- BaseClass.StaticMethod();
For Non-Static Methods: For non-static methods, you must create an instance of the derived class or use an existing instance of the base class if it is accessible.
Example : BaseClass instance = new DerivedClass();
instance.BaseMethod();
In summary , non-static base class methods require an instance, whereas static methods can be called directly on the class itself.
Priya ChavadiyaPosted Jul 31, 2024, 3:16 AM EDT
I believe by using :base
Learner LifePosted Mar 12, 2024, 10:55 PM EDT
In many programming languages, including C#, you can't directly call a base class method without creating an instance of the derived class. The base class method belongs to a specific instance of the class, and you need that instance to invoke its methods.
However, if you're trying to access a static method of the base class (a method marked with the static keyword), you can call it using the base class name directly, without needing an instance of the class.
Alpesh ManiyaPosted Mar 11, 2024, 8:45 AM EDT


