dy53

导航

 
 1 package Javashiyan7a;
 2 public class Bike implements Vehicle {
 3     @Override
 4     public void start() {
 5         System.out.println("Bike start");
 6     }
 7 
 8     @Override
 9     public void stop() {
10         System.out.println("Car start");
11     }
12 }
 1 package Javashiyan7a;
 2 public class Car implements Vehicle{
 3     @Override
 4     public void start() {
 5         System.out.println("Car start");
 6     }
 7 
 8     @Override
 9     public void stop() {
10         System.out.println("Car stop");
11     }
12 }
 1 package Javashiyan7a;
 2 public class Test_Vehicle {
 3     public static void main(String[] args) {
 4         Car c=new Car();
 5         c.start();
 6         c.stop();
 7         Bike b=new Bike();
 8         b.start();
 9         b.stop();
10     }
11 }
1 package Javashiyan7a;
2 public interface Vehicle {
3     public abstract void start();
4     public abstract void stop();
5 }

-----------------------------------------------------
 1 package Javashiyan7b;
 2 
 3 public class Computer implements PlayGame{
 4     public Computer(){}
 5     public Computer(String brand, int price) {
 6         this.brand = brand;
 7         this.price = price;
 8     }
 9 
10     public String getBrand() {
11         return brand;
12     }
13 
14     public void setBrand(String brand) {
15         this.brand = brand;
16     }
17 
18     public int getPrice() {
19         return price;
20     }
21 
22     public void setPrice(int price) {
23         this.price = price;
24     }
25 
26     String brand;
27     int price;
28     @Override
29     public void platGame() {
30         System.out.println("使用"+price+"元的"+brand+"电脑玩游戏");
31     }
32     public void coding(){
33         System.out.println("使用"+price+"元的"+brand+"电脑开发JavaEE应用");
34     }
35 }
 1 package Javashiyan7b;
 2 
 3 public class Phone implements PlayGame{
 4     String brand;
 5     int price;
 6     public Phone(){}
 7     public Phone(String brand, int price) {
 8         this.brand = brand;
 9         this.price = price;
10     }
11 
12     public String getBrand() {
13         return brand;
14     }
15 
16     public void setBrand(String brand) {
17         this.brand = brand;
18     }
19 
20     public int getPrice() {
21         return price;
22     }
23 
24     public void setPrice(int price) {
25         this.price = price;
26     }
27 
28     public void call(){
29         System.out.println("在使用"+price+"元 华为手机打电话");
30     }
31     @Override
32     public void platGame() {
33         System.out.println("在使用"+price+"元 华为手机发短信");
34     }
35 }
1 package Javashiyan7b;
2 
3 public interface PlayGame {
4     public abstract void platGame();
5 }
 1 package Javashiyan7b;
 2 
 3 public class TestGame {
 4     public static void main(String[] args) {
 5         Phone p=new Phone("华为",3000);
 6         p.platGame();
 7         p.call();
 8         Computer c=new Computer("雷神",6000);
 9         c.platGame();
10         c.coding();
11     }
12 }

 

 

posted on 2023-04-23 21:22  DY^^  阅读(22)  评论(0)    收藏  举报