hnjm.xxgl包:
//Animal.java文件
package hnjm.xxgl;
public class Animal {
protected String animalType = null;
public void printAnimalType() {
System.out.println("animalType : " + animalType);
}
void shout() {
System.out.println("shout");
}
protected void active() {
System.out.println("active");
}
}
//Cat.java文件
package hnjm.xxgl;
public class Cat extends Animal {
private void zhuoShu() {
System.out.println("zhuoShu");
}
}
//Test.java文件
package hnjm.xxgl;
public class Test {
public static void main(String[] args) {
Cat cat = new Cat();
cat.printAnimalType();
cat.shout();
cat.active();
//cat.zhuoShu(); //不允许访问
}
}
hnjm.xxgl.test包:
//Bird.java文件
package hnjm.xxgl.test;
import hnjm.xxgl.Animal;
public class Bird extends Animal {
public void sing() {
System.out.println("鸟儿在歌唱");
}
}
//Test.java文件
package hnjm.xxgl.test;
public class Test {
public static void main(String[] args) {
Bird bird = new Bird();
bird.printAnimalType();
//bird.shout(); //不允许访问
//bird.active(); //不允许访问
bird.sing();
}
}