package com.hanqi; public class Car { //属性 成员变量 //车的颜色 String YanSe; //车的品牌 String PinPain; //油箱容量 double YouXiangRongLiang; //当前油量 double DangQianYouLiang; //方法 函数 成员函数 public void jiaYou(double youliang){ DangQianYouLiang +=youliang; System.out.println("这次给" + YanSe + "的" +"PinPai" +"加了"+youliang+"升油"); }
package com.hanqi; public class tost { public static void main(String[] args) { //构建一个Car的实例,对象 Car xiali = new Car(); xiali.PinPain = "夏利"; xiali.YanSe = "红色"; xiali.jiaYou(40); //加油 } }
时间: 2024-10-27 01:29:26