2010/04/08

C# week11_1

Find bugs
Revised class

namespace ConsoleApplication27
{
class Program
{
static void Main(string[] args)
{
dog[] a = new dog[3];
dog d = new dog("tomy");
tomy t = new tomy("tomy", "white");
//change
tomykid tk = new tomykid("tomy","black");
a[0] = d;
a[1] =t;
a[2] = tk;
//change
foreach (dog k in a)
{
k.size();
k.bark();
}
}
}
public interface animal
{
void bark();
}
public class dog : animal
{
private string name;
public dog(string i)
{
name = i;
}
public void bark()
{
Console.WriteLine("dog barks");
}
public void size()
{
Console.WriteLine("size unknown");
}

}
public class tomy : dog
{
string color;
public tomy(string name, string color):base(name)
{
this.color=color;
}
public void bark()
{
Console.WriteLine("tomy barks");
}
public void size()
{
Console.WriteLine("small size");
}
}
public class tomykid : tomy
{
string haircolor;
//Change Constructor error
public tomykid(string name, string color):base(name, color)
{
this.haircolor = color;
}
public void bark()
{
Console.WriteLine("tomykid barks");
}
public void size()
{
Console.WriteLine("medium size");
}
}
}

0 件のコメント:

コメントを投稿

UA-9417263-1