sample9_13.java
来自「Java SE 6.0前11章示的示例代码,简单易学」· Java 代码 · 共 41 行
JAVA
41 行
package wyf.jc;
//声明接口
interface IFather
{
}
interface ISon extends IFather
{
}
//声明类
class Father
{
}
class Son extends Father implements ISon
{
}
public class Sample9_13
{
public static void main(String[] args)
{
//创建对象,进行instanceof测试
Son s=new Son();
if(s instanceof Son)
{
System.out.println("s指向的对象可以看作Son类型!!!");
}
if(s instanceof Father)
{
System.out.println("s指向的对象可以看作Father类型!!!");
}
if(s instanceof ISon)
{
System.out.println("s指向的对象可以看作ISon类型!!!");
}
if(s instanceof IFather)
{
System.out.println("s指向的对象可以看作IFather类型!!!");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?