class Box
{
public:
double length; // 长度
double width; // 宽度
double height; // 高度
double getVolume(void) //在类里面可以有自己的函数,为了方便封装成一个整体
{
return length * width* height;
}
};
getVolume就是类的成员函数 Box box1; // 声明 Box1,类型为 Box box1.getVolume(); //可以这样子使用
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/2880.html原文链接:https://javaforall.cn