功能
设计控制台应用程序,声明一个人类Person和一个动物类Animal,它们都包含有公有字段legs(腿的数目)和保护字段weight(重量),定义它们的对象并输出相关数据。
程序using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Person { // int x,y; public int legs = 2; protected int weight = 50; public void print() { Console.WriteLine("某人有{0}只腿,重量为{1}kg", legs, weight); } } class Animal { protected int weight = 120; public const int legs = 4; public void print() { Console.WriteLine("某动物有{0}只腿,重量为{1}kg", legs, weight); } } class Program { static void Main(string[] args) { Person ren = new Person(); Animal shou = new Animal(); ren.print(); shou.print(); } } }运行结果
如果想了解更多物联网、智能家居项目知识,可以关注我的程序设计专栏。
或者关注公众号。
编写不易,感谢支持。