GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  C#
Go To First  |  Previous Question  |  Next Question 
 C#  |  Question 359 of 436    Print  
How can i hide the base class method in derived class?

  
Total Answers and Comments: 4 Last Update: October 05, 2006     Asked by: sekhar 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
August 28, 2006 04:44:46   #1  
swati saxena        

RE: How can i hide the base class method in derived c...
by adding the new keyword.the member hides the inherited member with the same signature
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
August 28, 2006 05:34:58   #2  
preethi        

RE: How can i hide the base class method in derived c...
use sealed
 
Is this answer useful? Yes | No
August 29, 2006 23:49:06   #3  
blueconduct Member Since: August 2006   Contribution: 1    

RE: How can i hide the base class method in derived c...
sealed ?????Are you nuts!!!?????the new keyword is the correct answer.
 
Is this answer useful? Yes | No
October 05, 2006 19:27:16   #4  
satya rapelly        

RE: How can i hide the base class method in derived c...

Yes -

using System;

public class Parent

{

string parentString;

public Parent()

{

Console.WriteLine( Parent Constructor. );

}

public Parent(string myString)

{

parentString myString;

Console.WriteLine(parentString);

}

public void print()

{

Console.WriteLine( I'm a Parent Class. );

}

}

public class Child : Parent

{

public Child() : base( From Derived )

{

Console.WriteLine( Child Constructor. );

}

public new void print()

{

base.print();

Console.WriteLine( I'm a Child Class. );

}

public static void Main()

{

Child child new Child();

child.print();

((Parent)child).print();

}

}

The Child print() method hides the Parent print() method. The effect is the Parent print() method will not be called unless we do something special to make sure it is called.


 
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