📄 demoinstanceof.java
字号:
public class DemoInstanceOf
{
public static void main(String args[])
{
Employee emp = new Employee("Paul", "farm", 98764);
SalariedWorker sal = new SalariedWorker("Jeremy", "1119 6th St.", 550342, 1439);
HourlyWorker hW = new HourlyWorker("Scott", "cardboard box", 23456, 8, 21.5f);
if(emp instanceof Employee)
System.out.println("emp is good");
if(sal instanceof Employee)
System.out.println("sal is good");
if(hW instanceof Employee)
System.out.println("hw is good");
if(emp instanceof SalariedWorker)
System.out.println("emp is good");
if(sal instanceof SalariedWorker)
System.out.println("sal is good");
// if(hW instanceof SalariedWorker)
// System.out.println("hw is good");
if(emp instanceof HourlyWorker)
System.out.println("emp is good");
// if(sal instanceof HourlyWorker)
// System.out.println("sal is good");
if(hW instanceof HourlyWorker)
System.out.println("hw is good");
Object tempE = sal;
SalariedWorker sal2 = (SalariedWorker) tempE;
System.out.println(sal);
System.out.println(tempE);
System.out.println(tempE instanceof SalariedWorker);
SalariedWorker tempS = (SalariedWorker) tempE;
System.out.println(tempS);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -