Java instanceof 测试

	/**
	 * 测试instanceof
	 */
	private void testInstanceof() {
		Animal a = new Animal();
		Animal d = new Dog();
		Animal c = new Cat();
		
		boolean var = d instanceof Animal;
		DBG.plog("d instanceof Animal : " + var);
		var = d instanceof Cat;
		DBG.plog("d instanceof Cat : " + var);
		var = a instanceof Dog;
		DBG.plog("a instanceof Dog : " + var);
	}


输出:

d instanceof Animal : true
d instanceof Cat : false
a instanceof Dog : false


你可能感兴趣的:(Java instanceof 测试)