//代码1:包A中有一个动物类 package testa; public class Animal { protected void crowl(String c){ System.out.println(c); } } //代码2:包B中有两个类――猫类和鼠类 package testb; import testa.Animal; class Cat extends Animal{
} class Rat extends Animal{ public void crowl(){ crowl("zhi zhi"); //没有问题,继承了Animal中的protected方法――crowl(String) Cat cat=new Cat(); cat.crowl("miao miao"); //wrong, The method crowl(String) from the type Animal is not visible } }