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的使用
猜你喜欢
转载自blog.csdn.net/sunjinjuan/article/details/80605112
今日推荐
周排行