⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testinstanceof.java

📁 疯狂Java讲义_源码(含Java设计模式CHM
💻 JAVA
字号:


/**
 * Description:
 * <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * @author  Yeeku.H.Lee kongyeeku@163.com
 * @version  1.0
 */
public class TestInstanceof
{
	public static void main(String[] args) 
	{
		//声明hello时使用Object类,则hello的编译类型是Object,Object是所有类的父类
		//但hello变量的实际类型是String
		Object hello = "Hello";
		//String是Object类的子类,所以返回true。
		System.out.println("字符串是否是Object类的实例:" + (hello instanceof Object));
		//返回true。
		System.out.println("字符串是否是String类的实例:" + (hello instanceof String));
		//返回false。
		System.out.println("字符串是否是Math类的实例:" + (hello instanceof Math));
		//String实现了Comparable接口,所以返回true。
		System.out.println("字符串是否是Comparable接口的实例:" + (hello instanceof Comparable));
		String a = "Hello";
		//String类既不是Math类,也不是Math类的父类,所以下面代码编译无法通过
		System.out.println("字符串是否是Math类的实例:" + (a instanceof Math));
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -