当前位置:网站首页>C cat and dog
C cat and dog
2022-07-07 23:33:00 【Bobo in summer】

class //Pet Define a pet class (Pet):
{
string name; // Define private member fields in this class name Name and age Age , And set its corresponding public attributes ;
public string Name
{
get {
return name; }
set {
name = value; }
}
int age;
public int Age
{
get {
return age; }
set {
age = value; }
}
public virtual void cry()// This class includes two methods : It's called Cry(), Eat something Eat();
{
Console.WriteLine(" I'm a pet , My name is {0}, I {1} Year old ",this.name,this.age);
}
public virtual void eat()
{
Console.WriteLine(" I'm a favorite pet ");
}
public Pet() {
} // Complete the parameterless and parametric construction method of this class ;
public Pet(string name, int age)
{
this.name = name;
this.age = age;
}
}
class Dog:Pet// Define the subclass of a pet dog (Dog):
{
public override void cry() // Covering the parent class Cry(),Eat() Method ; Add ways to watch the door GuardEntrance()
{
Console.WriteLine(" I'm a dog , My name is {0}, I {1} Year old ",this.Name,this.Age);
}
public override void eat()
{
Console.WriteLine(" I like eating ");
}
public void GuardEntrance()
{
Console.WriteLine(" I like to watch the door , ha-ha ");
}
public Dog() {
} // Complete the parameterless and parametric construction method of this class ;
public Dog(string name, int age) : base(name, age) {
}
}
class Cat:Pet // Define the subclass of pet cats (Cat):
{
public override void cry() // Covering the parent class Cry(),Eat() Method ;
{
Console.WriteLine(" I'm a cat , My name is {0}, I {1} Year old ",this.Name,this.Age);
}
public override void eat()
{
Console.WriteLine(" I like it ");
}
public void GuardEntrance()// Increase the cat's own unique method of catching mice HuntMice();
{
Console.WriteLine(" I like reading ,");
}
public Cat() {
}// Complete the parameterless and parameterized construction of this class
public Cat(string name, int age) : base(name, age) {
}
}
Pet pet1 = new Dog(" Xiao Huang ",3);
pet1.cry();
pet1.eat();
((Dog)pet1).GuardEntrance();
Pet pet2 = new Cat(" The small white ", 2);
pet2.cry();
pet2.eat();
((Cat)pet2).GuardEntrance();
边栏推荐
猜你喜欢

2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion

B / Qurt Utilisateur Guide (36)

Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels

Progress broadcast | all 29 shield machines of Guangzhou Metro Line 7 have been launched

13、 System optimization

2021icpc Shanghai h.life is a game Kruskal reconstruction tree

Explain

三问TDM

B_ QuRT_ User_ Guide(36)

2022注册测绘师备考开始 还在不知所措?手把手教你怎么考?
随机推荐
1. Sum of two numbers
Lm12 rolling heikin Ashi double K-line filter
给出一个数组,如 [7864, 284, 347, 7732, 8498],现在需要将数组中的数字拼接起来,返回「最大的可能拼出的数字」
B_ QuRT_ User_ Guide(38)
Markdown
三问TDM
Conversion between commonsmultipartfile and file
HDU 4747 Mex「建议收藏」
Spark 离线开发框架设计与实现
移动端异构运算技术 - GPU OpenCL 编程(基础篇)
[untitled]
违法行为分析1
KeePass realizes automatic input of web pages
B_ QuRT_ User_ Guide(40)
系统设计概述
Archlinux install MySQL
Open source hardware small project: anxinco esp-c3f control ws2812
[STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware
How to change the formula picture in the paper directly into the formula in word
Count the top 10 films at the box office and save them in another file