Muhammad Imran Ansari
How can we call the base class method without creating an instance?
By Muhammad Imran Ansari in .NET on Mar 07 2024
  • Alpesh Maniya
    Mar, 2024 11

    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.

    • 1
  • Priya Chavadiya
    Jul, 2024 31

    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.

    • 0
  • Learner Life
    Mar, 2024 13

    I believe by using :base

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS