January 12, 2015

Oops output question series 1

1.What will be the output of following program?

 public class A
{
public virtual string GetName()
{
return "A";
}
}

public class B : A
{
public override string GetName()
{
return "B";
}
}

public class C : B
{
public new string GetName()
{
return "C";
}
}

static void Main(string[] args)
{
A instance = new C();
Console.WriteLine(instance.GetName());
Console.ReadLine();
}




2.What will be the output of following program?


   public class A
{
public A()
{
Console.WriteLine("From A");
}
}

public class B : A
{
public B(string X)
{
Console.WriteLine(X);
}
}

static void Main(string[] args)
{
B b = new B("From B");
Console.ReadLine();

}


No comments:

Post a Comment