1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
| package basic_0; public class BasicZc7 { public static void main(String[] args) { final double rate = 3.14; B b = new B(); b.setName("张三"); b.setAge(18); System.out.println(b.getName() + "---" + b.getAge()); b.show0(); b.show1(); System.out.println("---------------"); move0(Constant.UP); move1(Direction.DOWN); System.out.println("---------------"); People p = new Student(); Driver d = new Student(); Friend bf = new Student(); Driver a = new Student(); Driver a2 = new Teacher(); Friend b1 = new Student(); Friend b2 = new Teacher(); AImpl c = new AImpl(); c.go(); C.show(); } static abstract class A { private String name; private int age; public A() { System.out.println("A的无参构造器"); } public A(String name, int age) { this.name = name; this.age = age; } public abstract void show0(); public void show1() { System.out.println("show1方法"); } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } static class B extends A { @Override public void show0() { System.out.println("B类重写show方法"); } } public enum Direction { UP, DOWN, LEFT, RIGHT; } public class Constant { public static final int UP = 0; public static final int DOWN = 1; public static final int LEFT = 2; public static final int RIGHT = 3; } public static void move0(int direction){ switch (direction){ case Constant.UP : System.out.println("向上移动"); break; case Constant.DOWN : System.out.println("向下移动"); break; case Constant.LEFT : System.out.println("向左移动"); break; case Constant.RIGHT : System.out.println("向右移动"); break; default: System.out.println("输入有误"); } } public static void move1(Direction direction){ switch (direction){ case UP : System.out.println("向上移动"); break; case DOWN : System.out.println("向下移动"); break; case LEFT : System.out.println("向左移动"); break; case RIGHT : System.out.println("向右移动"); break; } } static class People{} interface Driver{} interface Friend{} static class Student extends People implements Driver, Friend{} static class Teacher implements Driver, Friend{} public interface C { default void go(){ System.out.println("==go方法执行了==="); run(); } private void run(){ System.out.println("==run方法执行了==="); } static void show(){ System.out.println("==show方法执行了==="); } } static class AImpl implements C{ } }
|