GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  DotNet
Go To First  |  Previous Question  |  Next Question 
 DotNet  |  Question 100 of 165    Print  
Can implement same method name in both baseclass And derived class with different action?

  
Total Answers and Comments: 3 Last Update: August 27, 2006     Asked by: Gopal 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
October 13, 2005 08:05:29   #1  
srilatha        

RE: Can implement same method name in both baseclass A...

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)

{

}

}


 
Is this answer useful? Yes | No
January 12, 2006 05:28:45   #2  
samiksc Member Since: October 2005   Contribution: 233    

RE: Can implement same method name in both baseclass A...

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.


 
Is this answer useful? Yes | No
August 27, 2006 14:36:32   #3  
VRod        

RE: Can implement same method name in both baseclass A...
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.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape