chapter21n3.java

来自「JAVA源代码程序aashjkjhkjhkjhjkhkj」· Java 代码 · 共 44 行

JAVA
44
字号
/** * * demonstration of instanceof, etc * * Written by: Roger Garside * * First Written: 5/Feb/97 * Last Rewritten: 5/Feb/97 * */import java.io.* ;import java.lancs.* ;import java.util.* ;public class Chapter21n3    {    public static void main(String[] args) throws Exception	{	funnyMethod("Hello Word") ;	funnyMethod(new Integer(42)) ;	funnyMethod(new Person()) ;	} // end of method main    public static void funnyMethod(Object x)	{	if (x instanceof String)	    {	    System.err.println("It was a String **" + x + "**") ;	    }        else if (x instanceof Integer)	    {	    System.err.println("It was an Integer **" + x + "**") ;	    }        else	    {	    System.err.println("It was a " + x.getClass().getName() + " **"						+ x + "**") ;	    }	} // end of method funnyMethod    } // end of class Chapter21n3

⌨️ 快捷键说明

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