当前位置:网站首页>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();
边栏推荐
- 电子设备行业智能供应链协同平台解决方案:解决低效, 赋能产业数字化升级
- 648. Word replacement
- Illegal behavior analysis 1
- Ros2 topic (03): the difference between ros1 and ros2 [01]
- SQL database execution problems
- MATLAB signal processing [Q & A essays · 2]
- LM12丨Rolling Heikin Ashi二重K线滤波器
- First week of July
- Cloud native data warehouse analyticdb MySQL user manual
- StringUtils工具类
猜你喜欢
The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way
Unity3d learning notes 5 - create sub mesh
Mobile heterogeneous computing technology - GPU OpenCL programming (basic)
给出一个数组,如 [7864, 284, 347, 7732, 8498],现在需要将数组中的数字拼接起来,返回「最大的可能拼出的数字」
RE1 attack and defense world reverse
Right click the idea file to create new. There is no solution to create new servlet
List. How to achieve ascending and descending sort() 2020.8.6
Live-Server使用
What if once again forgets the login password of raspberry pie? And you don't have a monitor yet! Today, I would like to introduce a method
2022 certified surveyors are still at a loss when preparing for the exam? Teach you how to take the exam hand in hand?
随机推荐
How to generate unique file names
New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
Explain
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
Solution of intelligent supply chain collaboration platform in electronic equipment industry: solve inefficiency and enable digital upgrading of industry
Freelink open source call center design idea
HDU 4747 mex "recommended collection"
谷歌浏览器怎么登录及开启同步功能
Three questions TDM
USB (XVIII) 2022-04-17
Unity3d learning notes 4 - create mesh advanced interface
Matlab SEIR infectious disease model prediction
How can we make money by making video clips from our media?
Summary of common methods of object class (September 14, 2020)
Coreseek:第二步建索引及測试
How to change the formula picture in the paper directly into the formula in word
Vs extension tool notes
Map operation execution process
v-for遍历对象
2021icpc Shanghai h.life is a game Kruskal reconstruction tree