User Tools

Site Tools


java:instanceof

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
java:instanceof [2017/02/14 09:16] gthanosjava:instanceof [2020/02/25 09:33] (current) – external edit 127.0.0.1
Line 20: Line 20:
 <code java InstanceofDemo.java> <code java InstanceofDemo.java>
 class InstanceofDemo { class InstanceofDemo {
-    public static void main(String[] args) {+  public static void main(String[] args) {
  
-        Parent obj1 = new Parent(); +    Parent obj1 = new Parent(); 
-        Parent obj2 = new Child();+    Parent obj2 = new Child();
  
-        System.out.println("obj1 instanceof Parent: " +    System.out.println("obj1 instanceof Parent: " 
-            + (obj1 instanceof Parent)); +      + (obj1 instanceof Parent)); 
-        System.out.println("obj1 instanceof Child: " +    System.out.println("obj1 instanceof Child: " 
-            + (obj1 instanceof Child)); +      + (obj1 instanceof Child)); 
-        System.out.println("obj1 instanceof MyInterface:+    System.out.println("obj1 instanceof MyInterface:
-            + (obj1 instanceof MyInterface)); +      + (obj1 instanceof MyInterface)); 
-        System.out.println("obj2 instanceof Parent: " +    System.out.println("obj2 instanceof Parent: " 
-            + (obj2 instanceof Parent)); +      + (obj2 instanceof Parent)); 
-        System.out.println("obj2 instanceof Child: " +    System.out.println("obj2 instanceof Child: " 
-            + (obj2 instanceof Child)); +      + (obj2 instanceof Child)); 
-        System.out.println("obj2 instanceof MyInterface:+    System.out.println("obj2 instanceof MyInterface:
-            + (obj2 instanceof MyInterface)); +      + (obj2 instanceof MyInterface)); 
-    }+  }
 } }
 </code> </code>
 +
 +Το παραπάνω πρόγραμμα εκτυπώνει
 +<code>
 +obj1 instanceof Parent: true
 +obj1 instanceof Child: false
 +obj1 instanceof MyInterface: false
 +obj2 instanceof Parent: true
 +obj2 instanceof Child: true
 +obj2 instanceof MyInterface: true
 +</code>
 +
 +|Προηγούμενο: [[ :java:comparable | Συγκρίνοντας αντικείμενα μεταξύ τους  ]] | [[:toc|Περιεχόμενα]] | Επόμενο: [[ :java:nested_classes | Εμφωλευμένες Κλάσεις ]]|
  
java/instanceof.1487063806.txt.gz · Last modified: 2017/02/14 09:16 by gthanos