简单练习java写类

 简单定义一个人类 简单的输出

public class People {
double height;
int age;
int sex;
String name;
 public People(int h,int a,int s,String n){
	 height = h;
	 age = a;
	 sex = s;
	 name = n;
 }
 public double getheight(){
	 return height;
 }
 public void setheight(double newheight){
	 height = newheight;
 }
void cry(){
	System.out.println("I'm crying");
}
void laugh(){
	System.out.println("I'm laughing");
}
void printbase(){
	System.out.println("我是-"+name);
	System.out.println("我的身高是:"+height+"cm");
	System.out.println("我的年龄是:"+age+"岁");
if (this.sex==0){
	System.out.println("我是男生");
}
else
	System.out.println("我是女生");
}


public static void main(String[] args) {
	People czz= new People(0,0,0,"czz");
	czz.height=165;
	czz.age=19;
	czz.sex=1;
	czz.laugh();
    czz.printbase();
	People cxa = new People(171,19,0,"cxa");
	cxa.laugh();
	cxa.printbase();
	People lilei = new People(0,0,0,"lilei");
	lilei.setheight(170);
	System.out.print("lilei的身高是"+lilei.getheight());
}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值