Click here to Skip to main content
15,888,208 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Is Method hiding a form of polymorphism?


What I have tried:

c#
Is Method hiding a form of polymorphism?
Posted
Updated 1-Dec-20 10:02am

1 solution

No. Try this:
C#
using System;

public class A 
    {
    public void x() 	
  	{
        Console.WriteLine("A:x");
        }
    }

public class B : A 
    {
    public new void x() 
	{
        Console.WriteLine("B:x");
        }
    }

public class Program
    {
    public static void Main() 
	{
        A a = new B();
        a.x();
        }
    }

If hiding was polymorphic, B:x would have been printed.
 
Share this answer
 
Comments
Member 14860567 2-Dec-20 10:37am    
I understood.Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900