继承
- 被继承的类为 基类 或者 父类
- 类 只能单继承 不可同时继承多类
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=" );
}
}
网友评论