package cn.tedu.producerconsumer;
public class Test5 {
public static void main(String[] args) {
M m=null;
N n=null;
System.out.println(m instanceof M); //false
System.out.println(n instanceof M); //false
System.out.println(n instanceof N); //false
M m1=new N();
N n1=new N();
L l=new L();
O o=new O();
System.out.println(m1 instanceof M); //true
System.out.println(n1 instanceof M); //true
System.out.println(n1 instanceof N); //true
System.out.println(l instanceof L); //true
System.out.println(l instanceof N); //true
System.out.println(l instanceof M ); //true
System.out.println(o instanceof M); //false
System.out.println(m1 instanceof N); //true
System.out.println(n1 instanceof L); //false
System.out.println(m1 instanceof L); //false
}
}
interface M{}
class N implements M {}
class L extends N{};
class O{}
class P{}
java中的Instanceof的使用
最新推荐文章于 2024-07-29 14:22:26 发布