package com.ly.lianxi4;
/**
* 狮子类
*
* 体重
* 年龄
* 描述
*
* 跑
*
* 吃
*/
public class Lion {
// 属性
private double weight;//体重
private int age;//年龄
private String desc;//描述
/**
* 跑
*/
public void run(){
System.out.println("lion 正在奔跑");
System.out.println(this.desc+"---"+this.age+"----"+this.weight);
}
/**
* 吃
* @param info 食物
*/
public void eat(String info){
System.out.println("loin 正在吃 ----"+ info);
}
//pu方法
public Lion() {
}
public Lion(double weight, int age, String desc) {
this.weight = weight;
this.age = age;
this.desc = desc;
}
//get/set
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
java 方法简介
最新推荐文章于 2024-09-14 21:48:00 发布
本文介绍了一个名为Lion的Java类,包含体重、年龄和描述属性,以及run和eat方法,展示了如何定义对象和其行为。
摘要由CSDN通过智能技术生成