繼承
- 被繼承的類為 基類 或者 父類
- 類 只能單繼承 不可同時(shí)繼承多類
Animal.java
public class Animal{
private String _animalName;
public Animal(String animalName){
this._animalName = animalName;
}
protected void skin(String skinName){
System.out.println( skinName );
}
protected void speack(String msg){
System.out.println( msg );
}
}
Dog.java
public class Dog extends Animal{
public Dog(String animalName){
super(animalName);
}
protected void skin(String skinName){
super.skin(skinName);
}
protected void speack(String msg){
super.speack(msg);
}
}
Park.java
public class Park{
public static void main(String[] args){
Dog dog = new Dog("dog");
dog.speack( "=dog=" );
}
}