Code example of equivalence between instanceof and class in Java
This paper mainly studies the equivalence between instanceof and class in Java, as follows.
The instanceof operator in Java is used to indicate whether an object is an instance of a specific class at run time. Instanceof returns a Boolean value to indicate whether the object is an instance of the specific class or its subclass.
Instance 1 (instanceof)
Interface person
Implementation class people
Subclass Xiaoming:
Main function
Note: the code in the above 2 will not report an error during compilation.
Operation results:
Example 2
The output is as follows:
The following conclusions can be drawn from the above tests:
summary
The above is all about the equivalence code example of instanceof and class in Java. I hope it will be helpful to you. Interested friends can continue to refer to other related topics on this site. If there are deficiencies, please leave a message to point out. Thank you for your support!