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");
}
}
==========================================================
This questions uses the same three class definitions as in the last question: class definition code. Also assume the declarations and initializations from the last question (variables x1, x2 and so on).
For each of the following function calls, tell which are syntactically valid and which are not. Also, if the function call is valid, tell what is printed to the console by that function call.
x1.f();
Valid Invalid
Output if valid
x2.f();
Valid Invalid
Output if valid
x1.h();
Valid Invalid
Output if valid
x2.h();
Valid Invalid
Output if valid
y1.f();
Valid Invalid
Output if valid
y2.f();
Valid Invalid
Output if valid
y1.h();
Valid Invalid
Output if valid
y2.h();
Valid Invalid
Output if valid
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
