Can we hide the derived class public method so that it is not accessible in Main() function in C#. We can’t change the accessors of the derived class method.
public class A
{
public void Add()
{
}
}
public class B : A
{
public void Multiply()
{
}
}
In main() method in C#
B b = new B();
b.mulitply(); // should give compile time error... Like method not founded.
Is there any way we can do it.
Why don’t you just just make the method private?
If you absolutely can’t change B, then the only thing I can think of is creating a full adapter class.
That will force you to “replicate” all the methods in B excepts the one you want.
If you ABSOLUTELY need the class to be “B” you’ll have to reverse engine it with reflector and change public field to private or protected.