Virtual-Override and New
Class Child inherits from Class Parent and has mehtod ShowVirtualOverride() and ShowNew() methods.
Please see the code snippet below and answer questions below:
class Parent
{
public virtual void ShowVirtualOverride()
{
Console.WriteLine("ParentVirtual");
}
public virtual void ShowNew()
{
Console.WriteLine("ParentNew");
}
}
class Child : Parent
{
public override void ShowVirtualOverride()
{
Console.WriteLine("ChildVirtual");
}
public new void ShowNew()
{
Console.WriteLine("ChildNew");
}
}
Question 1:
What is output of below code :
Parent objA = new Parent();
objA.ShowVirtualOverride();
objA.ShowNew();
Answer 1:
Output is below :
ParentVirtual
ParentNew
Question 2:
What is output of below code :
Parent objB = new Clild();
objB.ShowVirtualOverride();
objB.ShowNew();
Answer 2:
Output is below :
ChildVirtual
ParentNew
Question 3:
What is output of below code :
Child objC = new Child();
objC.ShowVirtualOverride();
objC.ShowNew();
Answer 3:
Output is below :
ChildVirtual
ChildNew
Question 4:
What is output of below code :
Child objD = new Parent();
objD.ShowVirtualOverride();
objD.ShowNew();
Answer 4:
This gives compilation error
Popular Posts
-
Answer : WCF belongs to System.ServiceModel
-
Different types of assemblies are : Static and Dynamic assemblies Private and Shared assemblies Single file and Multiple file assemblies ...
-
Authorization is used to determine whether user has access to resource or not. There are two ways to authorize a resource : File authoriza...
-
Operation behaviour are scoped at Operation level. It is used for transaction flow , serialization , parameter handling.
-
Different type of method parameters in C# are : Value Parameter Reference Parameter Output Parameter
-
Abstract class has following features : cannot be instantiated contain abstact methods and properties cannot modify abstract class with s...
-
OOPs concepts that C# supports are : Abstraction : is a process that involves identifying the crucial behavior of an object and eliminatin...
-
Characteristics of well designed normalized database are : Table should have identifier Table should store data for single type of entity...
-
There are five types of contracts : Service Contract Operation Contract Data Contract Message Contract Fault Contract Please refer be...
No comments:
Post a Comment