Program to implement parameterized constructors in c#
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication30
{
class a
{
public a()
{
Console.WriteLine("constructor--base class a");
}
public a(int g, int h)
{
Console.WriteLine("Parametrised constr...base class a");
s = g;
d = h;
}
~a()
{
Console.WriteLine("destructor--base class a");
}
public int s, d;
public void display()
{
Console.WriteLine(s);
Console.WriteLine(d );
}
}
class b : a
{
int r = 56;
int s = 23;
public b() :base(45,78)
{
Console.WriteLine("constructor--derived class b");
}
public b(int g, int h) : base (12,6)
{
Console.WriteLine("Parametrised constr...base class a");
s = g;
d = h;
}
~b()
{
Console.WriteLine("destructor--derived class b");
}
}
}
class c:a
{
static void Main(string[] args)
{
b b1 = new b();
b b2 = new b(56, 89);
b1.d = 34;
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment