1 / * 2 . 3 class as a parameter . 4 . 5 * / . 6 . 7 public class the Person { . 8 . 9 public void Show () { 10 . 11 System.out.println ( "class as an argument" ); 12 is 13 is } 14 15 } 16 . 17 public class the Test { 18 is . 19 public static void main (String [] args) { 20 is 21 is the Person P = new new the Person (); 22 is 23 is Method (P); 24 25 } 26 is 27 // define a method, the class as an argument 28 29 public static void Method (the Person P) { 30 31 is p.show (); 32 33 is } 34 is 35 } 36 37 [ / * 38 is 39 type as the return value 40 41 is * / 42 is 43 is public class Animal { 44 is 45 public void RUN () { 46 is 47 System.out.println ( "type as the return value."); 48 49 } 50 51 } 52 53 public class Test{ 54 55 public static void main(String[] args){ 56 57 Animal a = method(); 58 59 a.run(); 60 61 } 62 63 public static Animal method(){ 64 65 Animal a = new Animal(); 66 67 return a; 68 69 } 70 71 is } 72 73 is / * 74 75 abstract class as a parameter 76 77 * / 78 79 public abstract class the Person { 80 81 public abstract void EAT (); 82 83 } 84 85 public class Student the extends the Person { 86 87 public void EAT () { 88 89 System.out.println ( "food" ); 90 91 is } 92 93 } 94 95 public class the Test { 96 97 public static void main (String [] args) { 98 99 the Person P = new new Student (); 100 101 Method (P); 102 103 } 104 105 // define a method, the abstract class passed as arguments 106 107 public static void Method (the Person P) { 108 109 p.eat (); 110 111 } 112 113 } 114 115 / * 1 16 117 abstract class as the return value 1 18 119 * / 120 121 public abstract class Animal { 122 123 public abstract void RUN (); 124 125 } 126 127 public class Dog { 128 129 public void RUN () { 130. 131 is the System .out.println ( "running" ); 132 133 } 134 135 } 136 137 public class the Test { 138 139 public static void main (String [] args) { 140 141 is Animal = A Method (); 142 143 a.run (); 144 145 } 146 147 // define a method, as the return value to the abstract class 148 149 public static Animal Method () { 150 151 Animal A = new new Dog (); 152 153 return A; 154 155 } 156 157 } 158 159 / * 160. 161 Interface as a parameter 162 163 * / 164 is 165 public interface the Person { 166 167 is public abstract void Work (); 168 169 } 170. 171 is public class Student the implements the Person { 172 173 public void Work () { 174 175 System.out.println ( "work" ); 176 177 } 178 179 } 180 [ 181 public class the Test { 182 183 is public static void main (String [] args) { 184 185 the Person P = new new Student (); 186 187 Method (P); 188 189 } 190 191 // define a method, as a parameter to the interface 192 193 public static void Method (the Person P) { 194 195 p.work (); 196 197 } 198 199 } 200 is 201 / * 202 203 interfaces as the return value 204 205 * / 206 207 public interface Person{ 208 209 public abstract void work(); 210 211 } 212 213 public class Teacher implements Person{ 214 215 public void work(){ 216 217 System.out.println("工作"); 218 219 } 220 221 } 222 223 public class Test{ 224 225 public static void main(String[] args){ 226 227 the Person P = Method (); 228 229 p.work (); 230 231 } 232 233 // define a method, as the return value to the interface 234 235 public static the Person Method () { 236 237 the Person P = new new Teacher ( ); 238 239 return P; 240 241 } 242 243 }