Kalıtım(inheritance)
Form1.cs
namespace kalitim1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SATILANARABA araba2 = new SATILANARABA();
araba2.fiyat = Convert.ToInt32(textBox5.Text);
araba2.satinAlanKişi = textBox4.Text;
araba2.motorGucu = textBox3.Text;
araba2.marka = textBox2.Text.ToUpper();
araba2.Model = Convert.ToInt32(textBox1.Text);
label6.Text = Math.Abs(araba2.fiyat).ToString(); //Math kütüphanesinden Abs fonksiyonu
label7.Text = araba2.satinAlanKişi;
label8.Text = araba2.motorGucu;
label9.Text = araba2.marka;
label10.Text = araba2.Model.ToString();
}
}
}
public class ARABA
{
public string motorGucu; //İstemirse üzerinde herhangi bir aritmetiksel işlem olmadığı için string olarak tanımlanabilir.
private int model;
public string marka;
public int Model
{
get { return model; }
set {
//if (value>0)
//{
// model = value;
//}
//else
//{
// value = 0;
//}
model = Math.Abs(value);
}
}
}
class SATILANARABA:ARABA
{
public string satinAlanKişi;
public int fiyat;
}