c# - What is use of Parent object instantiating with child class -
please tell me of parent object instantiating child class like:
public class { public a() { console.writeline("a"); } public virtual void method() { console.writeline("am"); } } public class b : { public b() { console.writeline("b"); } public new void method() { console.writeline("bm"); } public void method1() { console.writeline("bm1"); } } class program { static void main(string[] args) { obj = new b();// use of it? obj.method(); console.read(); } private void methodp1() { } } please tell me use of parent obj = new child(); can call public methods of parent class possible using parent obj = new parent();
is possible: child obj = new parent() ?
please tell me use of parent obj = new child(); can call public methods of parent class possible using parent obj = new parent();
this basis polymorphism: imagine have several child classes inherit parent class. want use these child classes through interface / methods defined on parent class, without worrying implementation details in each child class (each might different, same overall semantics).
this possible because child class has relationship parent class since child inherits parent.
Comments
Post a Comment