Last active
January 3, 2016 18:08
-
-
Save rajeevprasanna/8499735 to your computer and use it in GitHub Desktop.
instanceOf Example
This file contains 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
package inheritanceIsaAndHasA; | |
//Refer : https://gist.github.com/rajeevprasanna/8499735 | |
public class InstanceOfExampleTest { | |
public static void main(String[] args) { | |
Test t1 = new Test(); | |
Test t2 = new Test(); | |
if (!t1.equals(t2)) {// equals compares references | |
System.out.println("they're not equal"); | |
} | |
if (t1 instanceof Object) {// check if object is part of Test class | |
// inheritance tree. | |
System.out | |
.println("t1's an Object because every class in java is subclass of object"); | |
// from Java doc :Class Object is the root of the class hierarchy. | |
// Every class has Object as a superclass. All objects, including | |
// arrays, implement the methods of this class. | |
//Refer : http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html | |
} | |
} | |
public static class Test { | |
// Test class | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment