예제 #1
0
        static void Main(string[] args)
        {
            Dog aDog = new Dog();
            Console.WriteLine(aDog.ToString());

            Dog myDog = new Dog("Fido");
            myDog.Weight = 45;
            myDog.Noise();
            Console.WriteLine(myDog.ToString());

            Cat myCat = new Cat("Pus");
            myCat.Weight = 12;
            myCat.Noise();
            Console.WriteLine(myCat.ToString());
        }
예제 #2
0
        static void Main(string[] args)
        {
            Dog aDog = new Dog();

            Console.WriteLine(aDog.ToString());

            Dog myDog = new Dog("Fido");

            myDog.Weight = 45;
            myDog.Noise();
            Console.WriteLine(myDog.ToString());

            Cat myCat = new Cat("Pus");

            myCat.Weight = 12;
            myCat.Noise();
            Console.WriteLine(myCat.ToString());
        }
예제 #3
0
        static void Main(string[] args)
        {
            List <Dog> dogs = new List <Dog>();

            //List<Cat> cats = new List<Cat>();

            dogs.Add(new Dog());
            dogs.Add(new Dog());
            foreach (var item in dogs)
            {
                item.Eat();
                item.Sleep();
                item.Bark();
                Console.WriteLine();
            }
            Console.WriteLine();

            List <Cat> cats = new List <Cat>()
            {
                new Cat(), new Cat()
            };

            //cats.Add(new Cat());
            //cats.Add(new Cat());
            foreach (var item in cats)
            {
                item.Eat();
                item.Sleep();
                item.Meow();
                Console.WriteLine();
            }
            Console.WriteLine();

            Dog d = new Dog();

            //d.Private();
            //d.Protected();    //Program class는 같은 클래스도 아니고 파생 클래스도 아니다.
            d.Public();
            Console.WriteLine(d);            //Inheritans.Dog
            Console.WriteLine(d.ToString()); //Inheritans.Dog
            Console.WriteLine();

            string s = "홍길동";

            Console.WriteLine(s);            //홍길동
            Console.WriteLine(s.ToString()); //홍길동
            Console.WriteLine();

            //p..331
            List <Object> list = new List <object>(); //모든 클래스의 최상의 클래스는 object class.

            list.Add(new Dog());
            list.Add(new Cat());
            list.Add(123);
            list.Add(3.14);
            foreach (var item in list)
            {
                Console.WriteLine(item);
                Console.WriteLine(item.ToString());
            }
        }