package com.hanqi.test;
public class People {
private String name,sex;
private int age;
private double height;
public People(String n,String s,int a,double h)
{
name=n;
age=a;
sex=s;
height=h;
}
public void speak(String s)
{
System.out.println(s);
}
public void count(double c1,double c2)
{
System.out.println(c1+c2);
}
public String changeName(String n)
{
name=n;
return name;
}
public void show()
{
System.out.println("我叫"+name+",今年"+age+",性别:"+sex+",身高:"+height);
}
}
//主类
package com.hanqi.test;
public class TestP {
public static void main(String[] args) {
People p=new People("张三","男",18,180);
p.show();
p.speak("你好");
p.count(23, 45);
p.changeName("李四");
p.show();
}
}
//测试结果
我叫张三,今年18,性别:男,身高:180.0
你好
68.0
我叫李四,今年18,性别:男,身高:180.0