Question: Consider the following two class definitions: class ClassX { public virtual void f() { WriteLine(f in X); } public void g() { WriteLine(g in X);
Consider the following two class definitions:
class ClassX { public virtual void f() { WriteLine("f in X"); } public void g() { WriteLine("g in X"); } } class ClassY : ClassX { public override void f() { WriteLine("f in Y"); } public void h() { WriteLine("h in Y"); } } For each of the following declarations and initializations, tell which are syntactically valid and which are not.
ClassX x1 = new ClassX();
| Valid | Invalid |
ClassX x2 = new ClassY();
| Valid | Invalid |
ClassY y1 = new ClassX();
| Valid | Invalid |
ClassY y2 = new ClassY();
| Valid | Invalid |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
