public interface Demo04Anima {
String behavior = "行为是:" ;
void eat ( ) ;
void run ( ) ;
}
public class Demo04Cat implements Demo04Anima {
public void eat ( ) {
System. out. println ( behavior + "吃骨头" ) ;
}
public void run ( ) {
System. out. println ( behavior + "在散步" ) ;
}
}
public class Demo04test {
public static void main ( String[ ] args) {
Demo04Cat c1 = new Demo04Cat ( ) ;
c1. eat ( ) ;
c1. run ( ) ;
}
}
```java
public interface Demo05Animal {
String behavior = "动物在:" ;
void run ( ) ;
}
```java
```java
在这里插入代码片
public interface Demo05LandAnimal extends Demo05Animal {
void liveOnLand ( ) ;
}
```java
public class Demo05Cat implements Demo05LandAnimal {
@Override
public void run ( ) {
System. out. println ( "猫在跑" ) ;
}
@Override
public void liveOnLand ( ) {
System. out. println ( "在陆地上生活" ) ;
}
}
public class Demo05Test {
public static void main ( String[ ] args) {
Demo05Cat ca1 = new Demo05Cat ( ) ;
ca1. run ( ) ;
ca1. liveOnLand ( ) ;
System. out. println ( Demo05Animal. behavior) ;
System. out. println ( ca1. behavior) ;
System. out. println ( Demo05Animal. behavior) ;
}
}