当前位置:网站首页>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
- B_QuRT_User_Guide(36)
- MySQL Index Optimization Practice II
- 家用电器行业渠道商协同系统解决方案:助力家电企业快速实现渠道互联网化
- LeeCode -- 6. Z 字形变换
- [untitled]
- PHP uses Alibaba cloud storage
- 2022 certified surveyors are still at a loss when preparing for the exam? Teach you how to take the exam hand in hand?
- One week learning summary of STL Standard Template Library
- Coreseek: the second step is index building and testing
猜你喜欢
随机推荐
Sequence of entity layer, Dao layer, service layer and controller layer
Cloud native data warehouse analyticdb MySQL user manual
New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
[STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware
Map operation execution process
进度播报|广州地铁七号线全线29台盾构机全部完成始发
Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的
Tree background data storage (using webmethod) [easy to understand]
三问TDM
SAP HR 社会工作经历 0023
云原生数据仓库AnalyticDB MySQL版用户手册
V-for traversal object
Archlinux install MySQL
MATLAB signal processing [Q & A essays · 2]
ROS2专题(03):ROS1和ROS2的区别【01】
Vulnerability recurrence ----- 49. Apache airflow authentication bypass (cve-2020-17526)
Happy gathering time
[compilation principle] lexical analysis design and Implementation
Open source hardware small project: anxinco esp-c3f control ws2812