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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
| package basic_0; public class BasicZc6 { public static void main(String[] args) { Teacher t = new Teacher(); t.setName("微光zc"); t.setSkill("java、前端、网络工程"); t.setSex('男'); System.out.println(t.getName()); System.out.println(t.getSkill()); System.out.println(t.getSex()); System.out.println("------------------"); Fu fu = new Fu(); fu.method(); fu.protectedMethod(); fu.publicMethod(); System.out.println("------------------"); Student s1 = new Student("张三", '男', 23); System.out.println(s1); Student s2 = new Student("二壮", '女', 19, "北京大学"); System.out.println(s2); System.out.println("------------------"); People pig = new Student(); pig.cry(); System.out.println(pig.getName()); } public static class People { private String name; private char sex; public void cry(){ System.out.println("歪比巴伯,rua~~~");} public String getName() { return name; } public void setName(String name) { this.name = name; } public char getSex() { return sex; } public void setSex(char sex) { this.sex = sex; } public People(){ } public People(String name, char sex) { this.name = name; this.sex = sex; } } public static class Student extends People{ private String name; private char sex; private int age; private String schoolName; @Override public void cry(){ System.out.println("啊吧啊吧啊吧~~");} public Student() { } public Student(String name, char sex, int age) { this(name, sex, age, "微光zc课堂"); } public Student(String name, char sex, int age, String schoolName) { this.name = name; this.sex = sex; this.age = age; this.schoolName = schoolName; } public String getName() { return name; } public void setName(String name) { this.name = name; } public char getSex() { return sex; } public void setSex(char sex) { this.sex = sex; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSchoolName() { return schoolName; } public void setSchoolName(String schoolName) { this.schoolName = schoolName; } @Override public String toString() { return "Student{" + "name='" + name + '\'' + ", sex=" + sex + ", age=" + age + ", schoolName='" + schoolName + '\'' + '}'; } } public static class Teacher extends People{ private String skill; public String getSkill() { return skill; } public void setSkill(String skill) { this.skill = skill; } public Teacher(){ } public Teacher(String name, String skill, char sex) { super(name, sex); this.skill = skill; } } class catPeople extends People{ @Override public void cry(){ System.out.println("喵喵喵~~"); } } public static class Fu { private void privateMethod(){ System.out.println("privateMethod"); } void method(){ System.out.println("method"); } protected void protectedMethod(){ System.out.println("protectedMethod"); } public void publicMethod(){ System.out.println("publicMethod"); } public static void main(String[] args) { Fu fu = new Fu(); fu.privateMethod(); fu.method(); fu.protectedMethod(); fu.publicMethod(); } } }
|