标签:
package com.hanqi.test; public class People { private String nema;//姓名 private int age;//年龄 private String sex;//性别 private double height;//身高 //创建所有属性的构造方法 public String getNema() { return nema; } public void setNema(String nema) { this.nema = nema; } 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 double getHeight() { return height; } public void setHeight(double height) { this.height = height; } //成员方法 public String getSay() { return "你好"; } public int getAccount(int a,int b)//计算a+b返回int { return a+b; }
People pp=new People(); pp.setNema("张三"); pp.setSex("男"); pp.setAge(18); pp.setHeight(1.80); System.out.println("姓名:"+pp.getNema()+"\r性别:"+pp.getSex()+"\r年龄:"+pp.getAge()+"\r身高"+pp.getHeight() +"\r他说:"+pp.getSay()+"\r23+45="+pp.getAccount(23, 45) ); pp.setNema("李四"); System.out.println("姓名改为:"+pp.getNema()); }
标签:
原文地址:http://www.cnblogs.com/diaozhaojian/p/5886647.html