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