C# DERS 24: KALITIMA GİRİŞ

class Program
    {
        static void Main(string[] args)
        {
            Customer customer = new Customer();
            customer.FirstName = "Emre"; // Customer, Persondan kalıtım aldığından persondaki propertyleri alabilecektir.
            customer.City = "İstanbul";

            Person[] persons = new Person[2]
            {
                new Customer{ FirstName="CustomerName" }, new Student{ FirstName="StudentName" }
            };

            foreach (var person in persons)
            {
                Console.WriteLine(person.FirstName);
            }         
        }
    }

    class Person
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }

    class Customer : Person
    {
        public string City { get; set; }
    }

    class Student : Person
    {
        
    }
using System;
class Kedi
{
protected int ayak_sayisi = 4;
//protected: Sadece bundan türetilen sınıfta görülür.
public void Av_Yakala()
{
Console.WriteLine(“kedi sınıfı avı yakaladı.”);
}

}
class Kaplan:Kedi
//Kalıtım işlemi bu şekilde gerçekleştiriliyor diyebiliriz. Kaplan

//Türeyen Kedi ise Türetilendir. Kaplana Derived Classta  diyebiliriz.

//Kediye ise Base Class yada Temel Class
{
public static void Main()
{
Kaplan k = new Kaplan();
//Neden instance Kedi değilde Kaplan çünkü kalıtım

//bu yüzden var :) Kalıtım yaptığımızda Kaplan yazarak Kediye 
//böyle erişebiliriz.
k.Av_Yakala();
Console.WriteLine(“Ayak Sayısı:{0}”, k.ayak_sayisi);
}