إ₰...👨🏻💻CODE👩🏻💻...₰❥
مثال بسيط يوضح مفهوم الوراثة :-
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp
{
class Human
{
string ONAME;
int OAGE;
public
void Initialize(string Name, int Age)
{
ONAME = Name;
OAGE = Age;
}
public
void ShowDitails()
{
Console.WriteLine("Name = {0}, Age = {1}", ONAME, OAGE);
}
}
class Teacher : Human
{
string OSchool, OTeachLevel;
public
Teacher(string School, string TeachLevel)
{
//This is Constructor!
OSchool = School;
OTeachLevel = TeachLevel;
}
public
void Teach()
{
}
public
void MakeTest()
{
}
}
class Employee : Human
{
string OInstitution, OStudyLevel;
public
Employee(string Institution, string StudyLevel)
{
//This is Constructor!
OInstitution = Institution;
OStudyLevel = StudyLevel;
}
public
void Work()
{
}
public
void Bribe()
{
}
public
void GetPromoted()
{
}
}
class Engineer : Human
{
string OCompany, OSpecialty;
public
Engineer()
{
}
public
Engineer(string Company, string Specialty)
{
//This is Constructor!
OCompany = Company;
OSpecialty = Specialty;
}
public
void Work()
{
}
}
class Program
{
static void Main(string[] args)
{
string Name = "wasam";
int Age = 20;
string Company = "None";
string Speciality = "IT";
Engineer O = new Engineer(Company, Speciality);
O.Initialize(Name, Age);
O.ShowDitails();
O.Work();
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊
@barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Name = wasam, Age = 20