java接口

2021-03-14 19:34

阅读:838

标签:printer   over   大小   code   open   rgba   size   ftp   The   

 1 package inter;
 2 
 3 public abstract class Door {
 4        abstract void openDoor();
 5        abstract void closeDoor();
 6 }
 7 
 8 
 9 package inter;
10 
11 public interface Lock {
12        void openLock();
13        void closeLock();
14 }
15 
16 package inter;
17 
18 public class TheftProofDoor extends Door implements Lock {
19 
20    @Override
21       void openDoor() {
22           System.out.println("开门...");
23       }
24 
25       @Override
26       void closeDoor() {
27           System.out.println("关门...");
28       }
29 
30       @Override
31       public void openLock() {
32           System.out.println("开锁...");
33       }
34 
35       @Override
36       public void closeLock() {
37           System.out.println("关锁...");
38       }
39 
40 }
41 
42 
43 package inter;
44 
45 public class Test {
46 
47   public static void main(String[] args) {
48     TheftProofDoor door=new TheftProofDoor();
49         // //回家:开锁 开门 关门 关锁
50     door.openLock();
51     door.openDoor();
52     door.closeDoor();
53     door.closeLock();
54   }
55 
56 }
 1 package inter_1;
 2 
 3 public interface InkBox {
 4        void printColor();//约定:可以打印任意颜色
 5 }
 6 
 7 
 8 
 9 package inter_1;
10 
11 public interface Paper {
12        void printSize();//约定:打印时必须知道纸张大小
13 }
14 
15 
16 package inter_1;
17 
18 public class PrinterA implements InkBox,Paper{
19 
20   @Override
21   public void printSize() {  
22       System.out.println("A4纸张");
23   }
24 
25   @Override
26   public void printColor() {
27     System.out.println("彩色");
28   }
29   
30 
31 }
32 
33 
34 package inter_1;
35 
36 
37 public class PrinterB implements InkBox,Paper {
38     @Override
39     public void printColor() {
40         System.out.println("黑白");
41     }
42 
43     @Override
44     public void printSize() {
45         System.out.println("B5纸张");
46     }
47 }
48 
49 package inter_1;
50 
51 public class Test {
52 
53   public static void main(String[] args) {
54     PrinterA a=new PrinterA();
55     a.printColor();
56     a.printSize();
57     
58     PrinterB b=new PrinterB();
59     b.printColor();
60     b.printSize();
61   }
62 
63 }

 

java接口

标签:printer   over   大小   code   open   rgba   size   ftp   The   

原文地址:https://www.cnblogs.com/dss-99/p/14016894.html


评论


亲,登录后才可以留言!