面向对象的练习

 1 package 汽车;
 2  class Car{
 3     String name;
 4     int wheel;
 5     String color;
 6     //构造方法//
 7     public Car(String name,int wheel,String color)//成员变量//
 8     {
 9         this.name=name;
10         this.wheel=wheel;
11         this.color=color;
12     }
13     //成员方法//
14     public void run() {
15        if(wheel>=4){
16             System.out.println(name+wheel+"个轮子飞快跑起来..");
17         }else{
18             System.out.println(name+"不够4个轮子了,赶快去修理");
19         }
20     }
21 } 
22 class CarFactory{
23     String name;
24     String address;
25     String tell;
26     public void repair(Car c) {
27         if(c.wheel>=4) {
28             System.out.println("车子没问题不要修嘞!");
29         }
30         else
31         {  
32             c.wheel = 4;
33             System.out.println("修好了,给钱!!");
34         }
35     }
36 }
37 public class DemoX {
38    public static void main(String args[]) {
39        Car c = new Car("陆虎",4,"黑色");
40        System.out.println(c.name+"是"+c.color+c.wheel+"轮胎");
41         //给车对象赋予属性值
42         
43         for(int i = 0 ; i<100 ; i++){
44             c.run();
45         }
46         c.wheel = 3;
47         c.run();
48         CarFactory f = new CarFactory();
49         f.name = "集群宝修车厂";
50         f.address = "韵泰商业广场一楼";
51         f.tell = "020-1234567";
52          System.out.println(f.name+"在"+f.address+"!!!"+"联系电话是"+f.tell);
53         f.repair(c);
54         c.run();
55         
56    }
57 
58 }

 

转载于:https://www.cnblogs.com/0929-luoyang/p/11312723.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值