• 2021-04-14 问题

    在C++中,类的成员都有相应的访问级别,设有一个类定义如下: class CStudent { private: char myname[15]; float myheight; public: int myid; public: CStudent (); // 默认构造函数 CStudent (char *name,int height); // 用户自定义构造函数 void SetInfo(char *name,floatheight); void GetInfo(); ~ CStudent (); //析构函数 } 用语句CStudent s1;创建一个对象,则下列对象访问语句正确的是( )

    在C++中,类的成员都有相应的访问级别,设有一个类定义如下: class CStudent { private: char myname[15]; float myheight; public: int myid; public: CStudent (); // 默认构造函数 CStudent (char *name,int height); // 用户自定义构造函数 void SetInfo(char *name,floatheight); void GetInfo(); ~ CStudent (); //析构函数 } 用语句CStudent s1;创建一个对象,则下列对象访问语句正确的是( )

  • 2022-05-31 问题

    下列程序的输出结果为 class Box{ int length,width,height; public void setInfo(int l,int w,int h){ length = l; width = w; height = h; } public int volumn(){ return length*width*height; } public int area(){ return (length*width + length*height + width*height) * 2; } public String toString(){ return "Length:" + length + " width:" + width + " height:" + height + " volumn: " + volumn() + " area:" + area(); }} public class BoxTest { public static void main(String[] args) { Box b = new Box(); b.setInfo(5,2,4); System.out.println(b.toString()); }}

    下列程序的输出结果为 class Box{ int length,width,height; public void setInfo(int l,int w,int h){ length = l; width = w; height = h; } public int volumn(){ return length*width*height; } public int area(){ return (length*width + length*height + width*height) * 2; } public String toString(){ return "Length:" + length + " width:" + width + " height:" + height + " volumn: " + volumn() + " area:" + area(); }} public class BoxTest { public static void main(String[] args) { Box b = new Box(); b.setInfo(5,2,4); System.out.println(b.toString()); }}

  • 1