|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace inheritance
{
public partial
class
frmEmpWithVirtual : Form
{
public frmEmpWithVirtual()
{
InitializeComponent();
}
class Employee
// creating class employee
{
public int
EmpID
//define the property of variables EmpID
{
get;
set;
}
public string
Name
//define the property of variable Name
{
get;
set;
}
public string
FatherName //define the property of variable
FatherName
{
get;
set;
}
public string
Designation
//define the property of variable Designetion
{
get;
set;
}
public Employee()
//constructor of Employee class to give their default value
{
EmpID = 0;
Name = "";
FatherName = "";
Designation = "";
MessageBox.Show("Call Employee class constructor.....");
}
public virtual
void Display()
//creating virtual function called Display
{
MessageBox.Show("Employee class Display function....\nempleyee id.."
+ EmpID + "\nemployee name.." + Name +
"\nemployee father name..." + FatherName +
"\nemployee desigination..." + Designation);
}
}
class Type :
Employee
//child class Type inherrite the base class
Employee
{
public string
TypeName
//define the property of Type_Name
{
get;
set;
}
public Type()
//constructor of Type class
{
TypeName = "Employee";
MessageBox.Show("Call Type class constructor.....");
}
public override
void Display()//Override
the function called Display
{
MessageBox.Show("Employee class Display function....\nempleyee id.."
+ EmpID + "\nemployee name.." + Name +
"\nemployee father name..." + FatherName +
"\nemployee desigination..." + Designation +"\nEmployee Type.."+ TypeName);
}
}
private void
buttonSubmit_Click(object sender,
EventArgs e)
{
Employee t1 =
new Employee();
//creating object of Employee class
t1.EmpID = Int32.Parse(txtEmpId.Text);
t1.Name = txtName.Text;
t1.FatherName = txtEmpFatherName.Text;
t1.Designation = txtDesignation.Text;
t1.Display();
//Employee class function Display called
t1 = new Type();
//initialize the Type class with object of
Employee class
t1.EmpID = Int32.Parse(txtEmpId.Text);
t1.Name = txtName.Text;
t1.FatherName = txtEmpFatherName.Text;
t1.Designation = txtDesignation.Text;
t1.Display(); //type class function Display
called
Type t2 = new
Type(); //crating
object of Type class
t2.EmpID = Int32.Parse(txtEmpId.Text);
t2.Name = txtName.Text;
t2.FatherName = txtEmpFatherName.Text;
t2.Designation = txtDesignation.Text;
t2.TypeName = txtEmaployeetype.Text;
t2.Display();
//type class function Display called
}
}
}
|