Computer Language/유니티

추상 클래스

알 수 없는 사용자 2014. 5. 13. 17:14

using UnityEngine;

using System.Collections;


public class chap8 : MonoBehaviour {


abstract class Animal{

protected string name;

public Animal(string name){

this.name = name;

}

//protected string GetInfo(){return "Animail:name=" + name;}  error

public string GetInfo(){return "Animal:name=" + name;}

public abstract void Cry();

}

class Tiger:Animal{

public Tiger(string name):base(name){}

public override void Cry() { Debug.Log("Tiger Cry");}

}

// Use this for initialization

void Start () {

Tiger t1 = new Tiger("HODORI");

t1.Cry();

print (t1.GetInfo());

}

// Update is called once per frame

void Update () {

}

}