파일 목록
-
📁 10
-
📁 3
-
📁 4
-
📁 4-minicalc
-
📁 7
-
📁 parking manager
- 2.cs
- desktop.ini
- Title.png
- 객체지향 3대 특징(+1).txt
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace week10
{
internal class Program
{
static void Main(string[] args)
{
Dog dog = new Dog("개", 1);
dog.AddAge();
dog.Bark();
//dog.Meow();
//dog.Name = "개";
//dog.Age = 1;
Cat cat = new Cat("냥", 10);
//cat.Name = "냥";
//cat.Age = 2;
cat.AddAge();
//cat.Bark();
cat.Meow();
Animal animal = new Animal("뱀",2);
animal.AddAge();
//animal.Bark();
//animal.Meow();
//Console.WriteLine(dog.Age);
//Console.WriteLine(cat.Age);
List<Dog> dList = new List<Dog>();
List<Cat> cList = new List<Cat>();
dList.Add(dog);
//dList.Add(cat);
//dList.Add(animal);
cList.Add(cat);
//cList.Add(dog);
//cList.Add(animal);
List<Animal> aList = new List<Animal>(); //다형성 예
aList.Add(dog);
aList.Add(cat);
aList.Add(animal);
foreach(var a in aList){
a.AddAge();
//is 연산자를 써서 안정적으로 쓰는 법
if(a is Dog)
((Dog)a).Bark();
//걍 한방에 처리하는 법
Cat c = a as Cat; //TryParse와 유사함
if (c != null)
c.Meow();
//a.Meow()
}
}
}
}