Muhammad Imran Ansari
Can we declare an overridden method to be static if the original method is not static?

Can we declare an overridden method to be static if the original method is not static?

By Muhammad Imran Ansari in .NET on Mar 27 2023
  • Mohammad Sadikur Rahman
    Mar, 2023 30

    No, you cannot declare an overridden method to be static if the original method is not static . Overridden methods are members of a class that are redefined in a derived class with the same signature and return type. They are used to provide a different implementation of the same method in the base class. However, you cannot change the characteristics of the method, such as its access modifiers, its parameter list, its return type, or its static/non-static nature.

    • 2
  • Rajeev Kumar
    Jun, 2023 29

    No, you can’t declare an overridden method to be static if the original method is not static .

    • 0
  • Deepak Rawat
    Apr, 2023 13

    if the original method is not static, the overridden method cannot be declared as static because it would change the method signature and not be considered as an overridden method.

    • 0
  • Aleksandr Poploukhin
    Apr, 2023 11

    No, you can't override static method, because static method doesn't have reference to object and doesn't have reference to table with virtual methods.

    • 0
  • Rajkiran Swain
    Apr, 2023 3

    No, we cannot declare an overridden method to be static if the original method is not static in most programming languages. When we override a method in a subclass, we are providing a new implementation of the same method defined in the superclass. The signature of the overridden method, including the method name, parameter types, and return type, must be exactly the same as the original method. This means that if the original method is not static, we cannot change it to be static in the overridden method because it would change the signature of the method.

    However, in some programming languages, such as C#, we can declare a static method in a subclass with the same name and signature as a non-static method in the superclass, but this is not considered overriding. Instead, it is called hiding or shadowing, and it can lead to confusion and errors in the code. It is generally recommended to avoid hiding or shadowing methods in this way and to use proper method overriding instead.

    • 0
  • Shivakumara M
    Mar, 2023 29

    Yes we decare

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS