java:instanceof
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
java:instanceof [2017/02/14 09:16] – gthanos | java:instanceof [2020/02/25 09:33] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Τελεστής instanceof ====== | ====== Τελεστής instanceof ====== | ||
- | Ο τελεστής '' | + | Ο τελεστής '' |
<code java MyInterface.java> | <code java MyInterface.java> | ||
Line 20: | Line 20: | ||
<code java InstanceofDemo.java> | <code java InstanceofDemo.java> | ||
class InstanceofDemo { | class InstanceofDemo { | ||
- | | + | |
- | | + | |
- | Parent obj2 = new Child(); | + | Parent obj2 = new Child(); |
- | | + | |
- | + (obj1 instanceof Parent)); | + | + (obj1 instanceof Parent)); |
- | System.out.println(" | + | System.out.println(" |
- | + (obj1 instanceof Child)); | + | + (obj1 instanceof Child)); |
- | System.out.println(" | + | System.out.println(" |
- | + (obj1 instanceof MyInterface)); | + | + (obj1 instanceof MyInterface)); |
- | System.out.println(" | + | System.out.println(" |
- | + (obj2 instanceof Parent)); | + | + (obj2 instanceof Parent)); |
- | System.out.println(" | + | System.out.println(" |
- | + (obj2 instanceof Child)); | + | + (obj2 instanceof Child)); |
- | System.out.println(" | + | System.out.println(" |
- | + (obj2 instanceof MyInterface)); | + | + (obj2 instanceof MyInterface)); |
- | } | + | } |
} | } | ||
</ | </ | ||
+ | |||
+ | Το παραπάνω πρόγραμμα εκτυπώνει | ||
+ | < | ||
+ | obj1 instanceof Parent: true | ||
+ | obj1 instanceof Child: false | ||
+ | obj1 instanceof MyInterface: | ||
+ | obj2 instanceof Parent: true | ||
+ | obj2 instanceof Child: true | ||
+ | obj2 instanceof MyInterface: | ||
+ | </ | ||
+ | |||
+ | |Προηγούμενο: | ||
java/instanceof.1487063766.txt.gz · Last modified: 2017/02/14 09:16 by gthanos