Data Hiding
Members can be declared as newin a subclass.
They hideinherited members with the same name.
class A
{
public int x;
public void F() {...}
public virtual void G() {...}
}
class B : A {
public newint x;
public newvoid F() {...}
public newvoid G() {...}
}
B b = new B();
b.x = ...; // accesses B.x
b.F(); ... b.G(); // calls B.F and B.G
((A)b).x = ...; // accesses A.x !
((A)b).F(); ... ((A)b).G(); // calls A.F and A.G !
No comments:
Post a Comment