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 default value of bool in c#?

705


Is class reference type c#?

713


What is a class level variable in c#?

711


Why is .net so popular?

696


Can structs in c# have destructors?

739


What is the difference between C# 3.5 and C# 4.0?

722


What is singleordefault?

684


Where do we use static class in c#?

660


What is a Managed Code??

732


What is a bool in c#?

640


What is lazy loading entity framework?

698


What is a partial class. Give an example?

692


What are the benefits of using the aggregate method in linq?

699


Is it possible to restrict the scope of a field/method of a class to the classes in the same namespace?

696


What is the difference between console and windows application?

662