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 revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
java:instanceof [2017/02/14 09:18]
gthanos
java:instanceof [2017/03/10 08:23]
gthanos
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>
Line 50: Line 50:
 obj2 instanceof MyInterface: true obj2 instanceof MyInterface: true
 </code> </code>
 +
 +|Προηγούμενο: [[ :java:abstract_classes_vs_interfaces | Συγκρίνοντας Abstract Κλάσεις και Interfaces  ]] | [[:toc|Περιεχόμενα]] | Επόμενο: [[ :java:nested_classes | Εμφωλευμένες Κλάσεις ]]|
  
java/instanceof.txt · Last modified: 2020/02/25 09:33 (external edit)