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
-
New Data types in SQL Server 2008 are : DATE - occupies 3 bytes . Has accuracy of 1 day . Data stored in 'YYYY-MM-DD' format TIME...
-
Question : State whether below class relationship is correct or not . If not why ? class A: B {} class B: C {} class C: A {} Answer...
-
How to pass null values to stored procedure from code behind ? Pass the parameter’s value as DBNull.Value from code-behind.
-
Different validation controls in ASP.NET are as follows : RequiredFieldValidator CompareValidator RangeValidator RegularExpressionValida...
-
Different types of primary behaviours are as follows : Service Behaviour Endpoint Behaviour Operation Behaviour Callback Behaviour
-
Cache object belongs to System.Web.Caching namespace.
-
Authentication is process of obtaining credentials such as username and password and validating the credentials. There are 3 types of ASP....
-
Custom HTTPmodule is created for: URL rewriting Compression Specialized authentication and authorization Specialized logging
-
Types of DML statements : Select Insert Update Delete
-
Question : You and a group of programmers have written a new web application using Visual Studio.NET for a new client. The application trac...
No comments:
Post a Comment