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
-
Below is indexer declaration : modifier return type this [argument list] { get { // Get codes goes here } set { // Set codes goes h...
-
1. An indexer is identified by it's signature. But a property is identified it's name. 2. An indexer is always an instance member,...
-
You can add public events for Httpmodule using below syntax i.e ModuleName_OnEventName in Global.asax . Example Session_OnStart ( Obj...
-
The steps to create custom HTTP module are : Implement IHttpModule Interface Handle Init Method and register events one needs Handle t...
-
Use a delegate when: An eventing design pattern is used. • It is desirable to encapsulate a static method. The caller has no need access o...
-
Please do below steps to make SQLServer session mode to work properly : 1. To use SQLServer mode, you must first be sure the ASP.NET sessi...
-
Different access modifiers/specifiers in C# : Public - Any class or assembly can access Protected - Access is limited to the containing ...
-
Replication is the way to keep data synchronised in multiple datbases. SQL Replication consists of two important part : Publisher - Datab...
-
OOPs concepts that C# supports are : Abstraction : is a process that involves identifying the crucial behavior of an object and eliminatin...
-
public class Operation { public int Add ( int a , int b ) { return (a+b); } } We have to call above method using delegate Steps below : D...
No comments:
Post a Comment