File tree 1 file changed +27
-0
lines changed
java-23/src/main/java/com/ibrahimatay
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,29 @@ public static void main(String[] args) {
14
14
// 200 HTTP status code refers to a OK
15
15
// 403 HTTP status code refers to a Client Error
16
16
// 0 HTTP status code refers to a Unknown error
17
+
18
+ // An employee is calling me. class com.ibrahimatay.Employee
19
+ whoCallMe (new Employee ());
20
+
21
+ // An employee is calling me. class com.ibrahimatay.Boss
22
+ whoCallMe (new Boss ());
23
+
24
+ // Wrong number.
25
+ whoCallMe (null );
26
+ }
27
+
28
+ public static void whoCallMe (Human human ) {
29
+ if (human instanceof Employee employee ) {
30
+ System .out .printf ("An employee is calling me. %1$s%n" , employee .getClass ());
31
+ return ;
32
+ }
33
+
34
+ if (human instanceof Boss boss ) {
35
+ System .out .printf ("An employee is calling me. %1$s%n" , boss .getClass ());
36
+ return ;
37
+ }
38
+
39
+ System .out .println ("Wrong number." );
17
40
}
18
41
19
42
public static String getHTTPCodeDesc (int code ) {
@@ -34,3 +57,7 @@ public static String getHTTPCodeDesc(int code) {
34
57
};
35
58
}
36
59
}
60
+
61
+ interface Human {}
62
+ class Employee implements Human {}
63
+ class Boss implements Human {}
You can’t perform that action at this time.
0 commit comments