Created
November 18, 2009 12:11
-
-
Save tedheich/237775 to your computer and use it in GitHub Desktop.
Array examples for creating Java Objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ArrayEx { | |
public static void main(String []args) { | |
Object obj[] = new Object[3]; | |
for (int i=0;i < obj.length; i++ ) { | |
if (obj[i] instanceof Object) { | |
System.out.println("obj[" + i + "] = Object" ); | |
} | |
else { | |
System.out.println("obj[" + i + "] <> Object"); | |
} | |
} | |
} | |
} | |
class ArrayEx2 { | |
public static void main(String []args) { | |
Object obj[] = new Object[3]; | |
for (int j=0; j < obj.length ; j++) { | |
obj[j] = new Object(); | |
} | |
for (int i=0;i < obj.length; i++ ) { | |
if (obj[i] instanceof Object) { | |
System.out.println("obj[" + i + "] = Object" ); | |
} | |
else { | |
System.out.println("obj[" + i + "] <> Object"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment