stackoverflow1453

Programming&&Games&&Life

Archive for June, 2015

Inheritance

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Deneme
{
    class Program
    {
        static void Main(string[] args)
        {
            Nokta m = new Nokta(43, 55);
            m.kat_10();
            Console.WriteLine(m);

            Cember c = new Cember(3, 4, 2);
            Console.WriteLine(c.Alan());

            Console.WriteLine(c);

            Cember p = new Cember(1, 1, 1);
            Console.WriteLine(p);

            Silindir s = new Silindir(1, 1, 1, 5);
            Console.WriteLine(s);            

        }
    }
}


///////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Deneme
{
    class Nokta
    {
        int x;
        int y;

        public Nokta(int a,int b)
        {
            x = a;
            y = b;
        }

        public override string ToString(){

            return x.ToString()+y.ToString();
        }

        public void kat_10(){

            x=x*10;
            y=y*10;
        }
    }
}

////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Deneme
{
    class Cember:Nokta
    {
        double yaricap;

        public Cember(int x, int y, int r):base(x,y)
        {
            yaricap = r;
        }

        public virtual double Alan()
        {
            return yaricap * yaricap * Math.PI;
        }

        public override string ToString()
        {
            return  base.ToString()+" Alan"+" "+Alan();
        }
    }
}


////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Deneme
{
    class Silindir:Cember
    {
        int yukseklik;

        public Silindir(int a,int b, int r, int h):base(a,b,r)
        {
            yukseklik=h;
        }

        public double Hacim(){

            return base.Alan()*yukseklik;
        }

        public override string ToString()
        {
            return "Silindirin özellikleri: "+ base.ToString()+ " Hacim "+ this.Hacim();
        }

    }
}