
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What is the difference between function overriding and method hiding in C#?
Overriding
Under overriding, you can define a behavior that's specific to the subclass type, which means a subclass can implement a parent class method based on its requirement.
Let us see an example of abstract classes that implements Overriding −
Example
using System; namespace PolymorphismApplication { abstract class Shape { public abstract int area(); } class Rectangle: Shape { private int length; private int width; public Rectangle( int a = 0, int b = 0) { length = a; width = b; } public override int area () { Console.WriteLine("Rectangle class area :"); return (width * length); } } class RectangleTester { static void Main(string[] args) { Rectangle r = new Rectangle(10, 7); double a = r.area(); Console.WriteLine("Area: {0}",a); Console.ReadKey(); } } }
Method Hiding (Shadowing)
Shadowing is also known as method hiding. The method of the parent class is available to the child class without using the override keyword in shadowing. The child class has its own version of the same function.
Use the new keyword to perform shadowing.
Let us see an example −
Example
using System; using System.Collections.Generic; class Demo { public class Parent { public string Display() { return "Parent Class!"; } } public class Child : Parent { public new string Display() { return "Child Class!"; } } static void Main(String[] args) { Child child = new Child(); Console.WriteLine(child.Display()); } }
- Related Articles
- What is the difference between method hiding and method overriding in Java?
- Difference between Method Overriding and Method Hiding in C#
- What is the difference between overriding and hiding in C#?
- What is the difference between method overloading and method hiding in Java?
- Difference between Method Overloading and Method Overriding in Java
- Difference Between Function Overloading and Overriding in C++
- What is the difference between overriding and shadowing in C#?
- What is the difference between a method and a function?
- What is method hiding in C#?
- Difference Between Data Hiding and Encapsulation
- Difference Between Abstraction and Data Hiding
- Difference between Method and Function in C#
- Difference between Method and Function in Python
- What is the difference between java method and native method?
- What is method hiding in Java and how to use it?

Advertisements