public class Car { int speed = 60;//速度 String color ="红色";//颜色 String name = "马沙利阿提";//名字 String direction;//行驶方向 //改变汽车速度的方法 public void driveCar() { speed = 50; name ="奥迪"; //方法体 } //汽车加速方法 public void driveCar(int p_seed) { int currentSpeed = speed+ p_seed; speed = currentSpeed; } //让方法有多个参数 public void driveCar(int p_speed,String p_direction) { speed = p_speed; direction = p_direction; } //一个有返回值的方法 public boolean isOverspeed() { if(speed>80) { return true;//返回是 }else { return false;//返回否 } } //Car类 } 方法:
表判断的返回值需要进行返回两个可能的返回值
|
|
来自: 新用户4769nJZn > 《java》