Your Ad Here

Saturday, June 14, 2008

Multi level inheritance

/* Write a program in C sharp on parameteried
construtor in multilevel inheritance*
*/
using System;

namespace Inherit
{
class Metals
{
string _metalType;
public Metals(String type)
{
_metalType = type;
Console.WriteLine("Metal\t\t:" + _metalType);
}
}

class SteelCompany : Metals
{
string _grade;
public SteelCompany(string grade) : base("Steel")
{
_grade = grade;
Console.WriteLine("Grade\t\t:" + _grade);
}
}
class Automobiles : SteelCompany
{
string _part;
public Automobiles(string part): base("Cast Iron")
{
_part = part;
Console.WriteLine("Part\t\t:" + _part);
}
public static void Main()
{
Automobiles auto = new Automobiles("Mercedes");
}
}
}

//Output

//Metal :Steel
//Grade :Cast Iron
//Part :Mercedes

No comments: