using System;
class Base
{
public Base()
{
Console.WriteLine("Printing the Base constructor 1!");
}
public Base(int x)
{
Console.WriteLine("Printing the Base constructor 2!");
}
}
class Derived : Base
{
// implicitly call the Base(int x)
public Derived() : base(10)
{
Console.WriteLine("Printing the Derived constructor!");
}
}
class MyClass
{
public static void Main()
{
// Displays the Base constructor 2 followed by Derived Constructor
Derived d1 = new Derived();
Console.ReadLine();
}
}
C# Code Explanation?
http://www.dougv.com/blog/2006/12/06/int...
Reply:well ask this question on vbforums.com and u will get the answer in a sec.
good luck
Reply:see when ever a derived class object is created... it will first create a reference of the base class... then it will create the remainin part of the derived class....
so for the above the output wud be...
Printing the Base constructor 2!
Printing the Derived constructor!
since the base class is initiated first and then the derived class is !
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment