代码示例:
Elephant.java
package cn.zxj.question;
import java.math.BigDecimal;
public class Elephant {
private String varieties;
private BigDecimal weight;
public String getVarieties() {
return varieties;
}
public void setVarieties(String varieties) {
this.varieties = varieties;
}
public BigDecimal getWeight() {
return weight;
}
public void setWeight(BigDecimal weight) {
this.weight = weight;
}
}
Refrigerator.java
package cn.zxj.question;
public class Refrigerator {
boolean load(Object o){
if(o instanceof Elephant){
System.out.println("elephant 装载成功");
}else{
System.out.println("装载成功");
}
return true;
};
}
TestDemo.java
package cn.zxj.question;
public class TestDemo {
public static void main(String[] args){
Elephant elephant = new Elephant();
new Refrigerator().load(elephant);
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)