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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!