What is hiding in CSharp ?

Answer Posted / deep

Hiding is also called as Shadowing. This is the concept of Overriding the methods. It is a concept used in the Object Oriented Programming.
E.g.
public class ClassA {
public virtual void MethodA() {
Trace.WriteLine("ClassA Method");
}
}
public class ClassB : ClassA {
public new void MethodA() {
Trace.WriteLine("SubClass ClassB Method");
}
}
public class TopLevel {
static void Main(string[] args) {
TextWriter tw = Console.Out;
Trace.Listeners.Add(new TextWriterTraceListener(tw));

ClassA obj = new ClassB();
obj.MethodA(); // Outputs “Class A Method"

ClassB obj1 = new ClassB();
obj.MethodA(); // Outputs “SubClass ClassB Method”
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between User controls and Custom Controls?

550


Is c sharp open source?

489


What does immutable mean in c#?

506


what is difference between destruct or and garbage collection ?

511


What is type checking in c#?

512






What are the benefits of using windows services:

549


Explain the types of Polymorphism.

581


what are some characteristics of an array?

525


Difference between a sub and a function in c#.

541


In .NET which is the smallest unit of execution?

638


Why do we use ienumerable in c#?

484


What is a cs file?

522


Explain the importance and use of each, version, culture and publickeytoken for an assembly.

530


Why constructor is used in c#?

489


Define Final Class in C#

548