当前位置:网站首页>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();
边栏推荐
- sql 数据库执行问题
- 2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
- B_ QuRT_ User_ Guide(38)
- B_QuRT_User_Guide(39)
- 城联优品作为新力量初注入,相关上市公司股价应声上涨150%
- LDO voltage stabilizing chip - internal block diagram and selection parameters
- Cloud native is devouring everything. How should developers deal with it?
- Illegal behavior analysis 1
- Archlinux install MySQL
- 产业共融新势能,城链科技数字峰会厦门站成功举办
猜你喜欢
Markdown
深入理解Mysql锁与事务隔离级别
Right click the idea file to create new. There is no solution to create new servlet
SAP HR 家庭成员信息
Mysql索引优化实战一
SRM supplier cloud collaborative management platform solution for building materials industry to realize business application scalability and configuration
KeePass realizes automatic input of web pages
js 获取对象的key和value
New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
随机推荐
云原生数据仓库AnalyticDB MySQL版用户手册
One week learning summary of STL Standard Template Library
Solve the problem of duplicate request resource paths /o2o/shopadmin/o2o/shopadmin/getproductbyid
Deep understanding of MySQL lock and transaction isolation level
B_QuRT_User_Guide(36)
Anxin can internally test offline voice module vb-01 to communicate with esp-c3-12f
[STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware
The text editor of markdown class should add colors to fonts (including typora, CSDN, etc.)
Experience sharing of system architecture designers in preparing for the exam: the direction of paper writing
LDO voltage stabilizing chip - internal block diagram and selection parameters
S2b2b mall solution of intelligent supply chain in packaging industry: opening up a new ecosystem of e-commerce consumption
做自媒体视频剪辑怎么赚钱呢?
B_ QuRT_ User_ Guide(38)
包装行业智能供应链S2B2B商城解决方案:开辟电商消费新生态
How can we make money by making video clips from our media?
移动端异构运算技术 - GPU OpenCL 编程(基础篇)
8.31 Tencent interview
USB (XVI) 2022-04-28
New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
B_QuRT_User_Guide(40)