Can we have the method in drived class with the same name
which is there in base class?

Answers were Sorted based on User's Feedback



Can we have the method in drived class with the same name which is there in base class?..

Answer / brijender p rana

It is possible to hide the base class method with the
derived class without using Virtual in base class and
Override keyword in subclass.there are some condition where
we have to redefine any method in derived class same name
in base class now question arise how can we hide the method
anwer is simple and logical we use the modifier NEW which
tell the compiler that derived class method "hides the base
class method. There are some example:
Class baseclass
{
Public void display()
{
console.writeline("base method");
}
}
class derived : baseclass
{
public new void display()
{
console.writeline("dervied mthod");
}
}
class test
{
public static void main()
{
derived d=new derivedclass();
d.display();
}
}

Is This Answer Correct ?    5 Yes 1 No

Can we have the method in drived class with the same name which is there in base class?..

Answer / alcheringa

yes we can have that. in order to invoke the method of the
same name we use base keyword before the method name.

if the method in the base class is virtual, which is the
case in most of the abstract classes we actually override
the method in the derived class.

it is therefore not a constraint in any way.

Is This Answer Correct ?    5 Yes 2 No

Can we have the method in drived class with the same name which is there in base class?..

Answer / satya

In C#, derived classes can contain methods with the same
name as base class methods.

*

The base class method must be defined virtual.
*

If the method in the derived class is not preceded by
new or override keywords, the compiler will issue a warning
and the method will behave as if the new keyword were present.
*

If the method in the derived class is preceded with
the new keyword, the method is defined as being independent
of the method in the base class.
*

If the method in the derived class is preceded with
the override keyword, objects of the derived class will call
that method instead of the base class method.
*

The base class method can be called from within the
derived class using the base keyword.
*

The override, virtual, and new keywords can also be
applied to properties, indexers, and events.

Is This Answer Correct ?    2 Yes 0 No

Can we have the method in drived class with the same name which is there in base class?..

Answer / ravindarjobs

have a look at this link.

http://msdn2.microsoft.com/en-us/library/6fawty39
(VS.80).aspx

Is This Answer Correct ?    0 Yes 0 No

Can we have the method in drived class with the same name which is there in base class?..

Answer / srinivas.r

YES its posiible to have a method with same name in the
derived class provide with
1. base class method should be hided by removing virtual
keyword.
2.use new keyword in derived class instead of override.

Is This Answer Correct ?    0 Yes 0 No

Can we have the method in drived class with the same name which is there in base class?..

Answer / shafi syed

yes we can have the method in drived class with the same
name which is there in the base class, But the condition is
both should have diffrent parameters.....that's it.

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More C Sharp Interview Questions

Is xamarin free?

0 Answers  


If we inherit a class do the private variables also get inherited ?

6 Answers   TCS,


What are extender provider components? Explain how to use an extender provider in the project.

0 Answers  


Method1() { int a=0, b=0, c=0; Monitor.Enter(this) c = 12; b = 3; a = c/b Moniter.Exit(this) } Method1() { int a=0, b=0, c=0; c = 12; b = 3; lock(this){ a = c/b } } Choose correct answer. a. Upon completion, Method1 and Method2 release the lock b. Upon Comletion, Method1 release the lcok and Method2 not. c. Upon Completion, Method2 release the lock and Method1 not. d. Upon Completion, neither Method1 or Method to release the lock.

1 Answers  


Distinguish between array and arraylist in c#?

0 Answers  


What is an enumerator in c#?

0 Answers  


What is sqldatareader c#?

0 Answers  


What?s the difference between the Debug class and Trace class?

2 Answers   Siebel,


Does c# support multiple class inheritance?

0 Answers  


Can we overload the main method in c#?

0 Answers  


Should I use double or float?

0 Answers  


Is string reference type / value type?

56 Answers   Accenture, Microsoft, Siemens,


Categories