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

How many parameters can a method have c#?

486


What are the types of class in c#?

494


How is a string immutable?

490


What is difference between mutable and immutable in c#?

449


What is a static class in c#?

506






How is lazy loading achieved?

495


What are the return types in c#?

493


Which language is used for desktop application?

483


Explain the difference between “constant” and “read-only” variables used in c#?

507


Can you call from an inherited constructor to a specific base constructor if both base class and an inheriting class has a number of overloaded constructors?

523


1. Describe page life cycle?

1576


Explain data types in c#?

518


What are the Types of compatabilities and explain them

518


how to prevent a class from being inherited in c#.net?

511


What is .net console?

530