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 yield c#?

559


What is double c#?

610


What is Implicit conversion in C#?

664


What is class and object c#?

556


what is IDisposal interface,IComparable,IEquatable,IFormatable

629






What is private and shared assembly?

637


Explain what are the steps for creating clr trigger?

544


How do you escape a character?

582


Why do we need escape characters?

565


What is string pool in c#?

638


Does c# do array bounds checking?

621


What is Global Assembly Cache (GAC) and what is the purpose of it? (How to make an assembly to public? Steps) How more than one version of an assembly can keep in same place?

669


Which types of inheritances does c# support?

544


What is difference between sleep () and wait ()?

574


Explain a MSIL ? Why is it appreciated by all developers?

672