C# Inheritance, adding new methods -
ok i've been searching while trying find anwer question difficult phrase asking here.
i'm inheriting class like
class (int a, int b, int c) public a(int a, int b, int c) { } class b : public b(int a, int b, int c) base: (a, b, c) public void blah(int something) { } why can't , :
b classb = new b(1,2,3); classb.blah(4); instead have do
public virtual void blah(int something) { } in class a, in class b:
public override void blah(int something) { //method used in b not a. } so though have no intention of ever using method in class still have declare virtual? if i'm inheriting class c : b what? have declare stuff in c?
your assumption has no meaning, @ least as understood.
consider following example:
public class base {} public class derived : base { public void derivedspecificmethod() { } } if
derived d = new derived(); //as specify in code example d.derivedspecificmethod(); //you can this. the virtual may need in case when write:
base b = new derived(); //note, use base here on left side of equation b.derivedspecificvirtualmethod(); //virtual method call
Comments
Post a Comment