简单回答c##

来源:百度知道 编辑:UC知道 时间:2024/06/17 09:10:26
谁能给我讲讲成员变量和 成员方法的关系?

都是成员....

成员类似于全局,就是在某个类下直接定义的变量或方法。
当创建类的对象时,可以直接用该类的对象访问成员变量和成员方法。
比如:
public class Apple()
{
string color;
public string getApple()
{
string str1="i want eat an apple";
return str1;
}
}
-------------------
另一个类:
public class People
{
public void eatApple()
{
Apple apple=new Apple();
apple.color="red";
string eatStr=apple.getApple();
}

}