using?System;using?System.Collections.Generic;using?System.Linq;using?System.Text;using?System.Threading.Tasks;?
namespace?PetShop
{
????struct?fish
????{
????????int?weight;
????????int?size;
????????int?type;
????}
????interface?ICatchMice????{
????????void?CatchMice();
????}
????interface?IClimbTree????{
????????void?climbTree();
????}
????abstract?public?class?Pet????{
????????public?Pet(string?name)
????????{
????????????_name?=?name;
????????}
????????protected?string?_name;
????????public?void?PrintName()
????????{
????????????Console.WriteLine("Pet's?name?is?"?+?_name);
????????}
????????//public?uint?age;????????//public?string?food;????????abstract?public?void?Speak();
????????virtual?public?void?Move()
????????{
?
????????}
???????
????}
????public?class?Dog:Pet????{
????????static?int?Num;
????????static?Dog()
????????{
????????????Num?=?0;
????????}
????????public?Dog(string?name):base(name)
????????{
????????????++Num;
????????}
????????new?public?void?PrintName()
????????{
????????????Console.WriteLine("寵物的名字是?"?+?_name);
????????}
????????sealed?override?public?void?Speak()
????????{
????????????Console.WriteLine(_name?+?"?is?speaking"?+?"?wow");
????????}
????????override?public?void?Move()
????????{
?
????????}
????????static?public?void?ShowNum()
????????{
????????????Console.WriteLine("Dog's?number?=?"?+?Num);
????????}
????}
????public?class?Labrador?:?Dog????{
????????public?Labrador(string?name):base(name)
????????{
?
????????}
????}
????public?class?Cat:Pet,ICatchMice,IClimbTree????{
????????public?Cat(string?name):base(name)
????????{
?????
????????}
????????override?public?void?Speak()
????????{
????????????Console.WriteLine(_name?+?"?is?speaking"?+?"?meow");
????????}
????????public?void?CatchMice()
????????{
????????????Console.WriteLine("?Catch?mice");
????????}
????????public?void?ClimbTree()
????????{
????????????Console.WriteLine("?Climb?tree");
????????}
????}
?
????class?Program????{
????????static?void?Main(string[]?args)
????????{
????????????Pet[]?pets?=?new?Pet[]?{new?Dog("Jack"),new?Cat("Tom")};
????????????//Pet?dog?=?new?Dog();????????????//dog.PrintName();????????????//dog.Speak();????????????////Pet?cat?=?new?Cat();????????????//cat.PrintName();????????????//cat.Speak();????????????for?(int?i?=?0;?i?<?pets.Length;?++i)
????????????{
????????????????pets[i].Speak();
????????????}
????????????Cat?c?=?new?Cat("Tom2");
????????????IClimbTree?climb?=?(IClimbTree)c;
????????????c.ClimbTree();
????????????climb.ClimbTree();
????????????ICatchMice?catchM?=?(ICatchMice)c;
????????????c.CatchMice();
????????????catchM.CatchMice();
?
????????????Dog.ShowNum();
????????}
????}
}

2022-06-03
的我
https://s.cnr.cn/index_sub.html?key=%E4%B9%B0%E7%90%83%E5%B9%B3%E5%8F%B0%E3%80%90%E5%AE%98%E7%BD%91%EF%BC%9AY%D0%92%E2%91%A1%E2%91%A4%E2%91%A1.%D0%A1%D0%A1%E3%80%91
2020-03-28
第一點(diǎn)錯(cuò)誤,派生類重寫基類的方法,基類沒有方法
?virtual? public void Speak()
? ? ? ? {
? ? ? ? ?}
第二點(diǎn)錯(cuò)誤,你聲明接口,
2019-07-09
好像類中寫的ClimbTree()方法是小寫的 調(diào)用的時(shí)候是大寫的吧
2018-10-27
? ? interface IClimbTree
? ? {
? ? ? ? void ClimbTree();
? ? }
大寫啊ClimbTree();