4e1548abe2
Part1
67 lines
1.5 KiB
C#
67 lines
1.5 KiB
C#
namespace Lesson3_封装_成员方法练习
|
|
{
|
|
enum E_Occupation
|
|
{
|
|
Student = 0,
|
|
Teacher = 1,
|
|
}
|
|
class Person
|
|
{
|
|
public string name;
|
|
public string age;
|
|
|
|
|
|
public void Speak(string str)
|
|
{
|
|
Console.WriteLine("{0}说了{1}", name, str);
|
|
}
|
|
public void Walk()
|
|
{
|
|
Console.WriteLine("{0}走了路", name);
|
|
}
|
|
public void Eat(Food food)
|
|
{
|
|
Console.WriteLine("{0}吃了{1},共计{2}卡路里", name, food.name, food.Calorie);
|
|
}
|
|
}
|
|
class Student
|
|
{
|
|
public string name;
|
|
public void Study()
|
|
{
|
|
Console.WriteLine("{0}学了习", name);
|
|
}
|
|
public void Eat(Food food)
|
|
{
|
|
Console.WriteLine("{0}吃了{1},共计{2}卡路里", name, food.name, food.Calorie);
|
|
}
|
|
}
|
|
class Food
|
|
{
|
|
public string name;
|
|
public int Calorie;
|
|
|
|
}
|
|
internal class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
Person p = new Person();
|
|
p.name = "Test";
|
|
p.Speak("hello");
|
|
p.Walk();
|
|
//p.Eat();
|
|
Student s = new Student();
|
|
s.name = "Test2";
|
|
s.Study();
|
|
//s.Eat();
|
|
|
|
Food bread = new Food();
|
|
bread.name = "Bread";
|
|
bread.Calorie = 200;
|
|
s.Eat(bread);
|
|
p.Eat(bread);
|
|
}
|
|
}
|
|
}
|