This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
publicclassMain{
publicstaticvoidmain(String[]args){
Dogdog=newDog("Buddy");
Catcat=newCat("Kitty");
Birdbird=newBird("Tweety");
// 调用 Pet 接口方法
dog.play();
cat.play();
// Bird 没有实现 Pet,所以不能调用 play()
bird.fly();
// 也可以通过 instanceof 检查
if(doginstanceofPet){
System.out.println(dog.getName()+" is a pet.");
}
if(!(birdinstanceofPet)){
System.out.println(bird.getName()+" is not a Pet implementation.");