标签:test 用法 public str html void main com down
instanceof是java中固有的关键字, 就像main, public一样,用法:aa instanceof AA 就是问aa是不是AA的一个实例, 是的话,就返回真。马 克 - t o - w i n:当用instance of测试时,马克-to-win:子类的指针是一个instance of父类, 返回值为真,见以下的例子。
例1.9.2---本章源码
class AMark_to_win {
}
class B {
}
class AA extends AMark_to_win {
}
public class Test {
public static void main(String[] args) {
AMark_to_win a = new AMark_to_win();
AMark_to_win aa = new AA();
B b = new B();
AA aaa = (AA) aa;
AA aaaa = new AA();
System.out.println(a instanceof AA);// false
System.out.println(aa instanceof AA);// true
System.out.println(a instanceof AMark_to_win);// true
System.out.println(b instanceof B);// true
System.out.println(aa instanceof AMark_to_win);// true//think of AMark_to_win aa=nul;马克-to-win:
System.out.println(aaa instanceof AA);// true
/* true aaa is an instance of AA,AA is a A, (is relationship. ) */
System.out.println(aaa instanceof AMark_to_win);
java中instanceof是怎么用的, 干什么使的,举例!
标签:test 用法 public str html void main com down
原文地址:https://www.cnblogs.com/mark-to-win/p/9693509.html