package liu0919; public class People { private double height;// 身高 private String name;// 名字 private int age;//年龄 private String sex;//性别 //成员方法 public double getHeight() { return height; } public void setHeight(double height) { this.height = height; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String xingwei(String xw) { return xw; } public int Jia(int a,int b) { return a+b; } public String Gaiming(String gm) { return gm; } }
package liu0919; public class Cishi_people { public static void main(String[] args) { People pe=new People(); pe.setName("张三"); System.out.println("姓名是:"+pe.getName()); pe.setSex("男"); System.out.println("性别是:"+pe.getSex()); pe.setAge(18); System.out.println("年龄是:"+pe.getAge()); pe.setHeight(1.80); System.out.println("身高是:"+pe.getHeight()); System.out.println("说出:"+pe.xingwei("你好!")); System.out.println("23+45="+pe.Jia(23, 45)); System.out.println("姓名改为:"+pe.Gaiming("李四")); } }
时间: 2024-10-12 12:48:55