mtwm.net
当前位置:首页 >> 编写一个pErson类 >>

编写一个pErson类

#include<iostream.h> class Person { public:Person(char *name="",int age=0) { m_name=name; m_age=age; } void SayHello() { cout<<"我叫"<<m_name<<","<<"年龄"<<m_age<<endl; } private: char * m_name; int m_age; }; class

class person{ String name; int height; int age; public boolean equals(person per){ boolean result=true; boolean bool1=false; bool=(this.name.equals(per.name)); boolean bool2=false; bool2=(this.height==per.height); boolean bool3=false; bool3=(this.

//CPerson类 class CPerson { protect: CString m_strName; UINT m_nAge; CString m_strSex; public: CPerson() //默认构造函数 { m_strName.Empty(); m_nAge = 22; m_strSex.Empty(); } CPerson(CString strName="",UINT nAge=22,CString

构造函数的命名必须和类名完全相同.在java中普通函数可以和构造函数同名,但是必须带有返回值;书写类:public class Person{ private String name; private String sex; public Person(){ System.out.println("调用了无参的构造函数"); }

先定义一个Object数组 Object[] obj = new Object[10]; 然后将生成的类放进数组中 obj[i]= new Person(); 将数组写到txt文件中要用到对象输入输出流,最好给Person类重写toString方法

Miss Smith:Hello,is that Peace Hotel?Reservstionist:Yes.Can I help you?Miss Smith: 12th to 16th,and just one suite.Can it be available?Reservstionist:Just a mimute please,

public class Person { private String name; private int age; public Person(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge()

package org.gg;public class Person { //封装是在程序上,隐藏对象的属性和实现细节,仅对外公开接口,控制在程序中属性的读和修改的访问级别 //注意 这里一定是private 防止外界对属性直接进行修改,另外也实现了隐藏 private Object eye;

public class Person{ } public class Student extends Person{ String xuhao; String banji; int age; } public class Teacher extends Person{ String zhicheng; String zhushouKecheng; } import java.util.*; public class Test{ public final static void main(String[]

class Person{ private String name, address; private int age;//get / set methods } ~ ~ ~

pdqn.net | jjdp.net | jamiekid.net | knrt.net | gpfd.net | 网站首页 | 网站地图
All rights reserved Powered by www.mtwm.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com