.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
abhays
Clintonzz
arronlee
mattyclown
cathyhill345


Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.


Post New Question Subscribe to Interview Questions
 
Quick Links For Interview Questions Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  OOPs  JQuery  JavaScript/VBScript
BiztalkPatten/Practices.IISWCFWPFWWF
NetworkingAptitudeOthers  All    
 

Interview Questions And Answers

This is the progam using inheritence, what is the order of calling constructors and what is the output?
Public Class ConstructorEx
Public Class Class1
Dim a As Integer
Sub New()
a = 1
Console.WriteLine("a in initialized in Class1")
End Sub
End Class

Public Class Class2
Inherits Class1
Dim b As Integer
Sub New()
b = 1
Console.WriteLine("b in initialized in Class2")
End Sub
End Class
Public Class Class3
Inherits Class2
Dim c As Integer
Sub New()
c = 1
Console.WriteLine("c in initialized in Class2")
End Sub
End Class

Shared Sub main()
'Creation of the object of type Class3
Dim c As New Class3()
Console.ReadLine()
End Sub
End Class

Author: Asha.MP          Posted Date: October 26, 2010    Category: ASP.Net     Points: 10

In this example creation of the object of type class3 calls the Class3 constructor and that constructor calls Class2 Constructor Class2 Calls Class1 Constructor.So first Class1 constructor will execute and then control will be trasfered to class2 constructor,After executing the class2 constructor the control will be treansfered to Class3 constructor.
means

Class1
|---->Sub New()---------------------|
| 'First it will execute <-----|
| End Sub |
| |
| Class2 |
|--->Sub New()----------------------|
| 'Second it will execute<-------|
| End Sub |
| |
| Class3 |
----Sub New()-----------------------|
'Third this will executes<-----|
End Sub

Means In the Creation of the object of type C, First Class1 Constuctor initializes the data, then class2 then class3.

So output of this program is
a in initialized in Class1
b in initialized in Class2
c in initialized in Class3

« Previous1Next »
 




Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend