数据和操作的封装

//定义了两个Student类的对象stud1,stud2,这里对象stud1,stud2是占空间的
//目前封装在类中的对象stud1和stud2都是对外界隐蔽的,外界不能调用它们,只有本对象中的函数display
//才可以引用本对象中的数据,这里就引出“接口”


//一般把“数据成员”隐含起来,把“成员函数”当做外界“接口”,从外界发一个命令,通知对象stud1执
//行其中的display函数,输出某一学生的有关数据
class Student
{
private:
int num;
char name[20];//把“数据成员”隐含起来
char sex;
public:
void display() //把“成员函数”当做外界“接口”
{
cout << "num:" << num << endl;
cout << "name:" << name << endl;
cout << "sex:" << sex << endl;
}
};
Student stud1, stud2;

相关文章:

  • 2021-07-16
  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2021-12-04
猜你喜欢
  • 2021-06-20
  • 2022-12-23
  • 2021-08-25
  • 2021-09-19
  • 2022-12-23
  • 2021-05-29
  • 2021-12-23
相关资源
相似解决方案