Can implement same method name in both baseclass And derived class with different action?

Showing Answers 1 - 3 of 3 Answers

srilatha

  • Oct 13th, 2005
 

method overloading is possible.

suppose baseclass class class1 is having method called getname(string name) this method can be overloaded in derived class class2:class1

{

void getmethod(int i,string name)

{

}

}

  Was this answer useful?  Yes

samiksc

  • Jan 12th, 2006
 

It is possible to 'override' a method with the same name and parameters and provide a different implementation in a derived class, if the base class declares the method as overridable. (override in C#)

It is also possible to use the 'new' keyword in C# to provide a different implementation of a method which may be or may not be declared as overridable by the base class.

The derived class also may use the same method name as in the base class and provide different parameter list and different implementation which will 'overload' the base class method. Here it is not necessary that the method be declared as overridable in the base class.

  Was this answer useful?  Yes

VRod

  • Aug 27th, 2006
 

Remember -> This is not recommended. Since the same-name method exists in both the base class and the derived class, with actions in both; therefore at runtime, any of these methods can be called by compiler, it's not in your control. Hence, if the purpose is to override, let only the derived class contain an action; else use different method names.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions