網(wǎng)站制作NEWS
編程作業(yè):利用面向?qū)ο蟮姆椒ň幊虒?shí)現(xiàn)如下結(jié)果輸出
/**
* @author Administrator
* 方法一
*/
public class Dog {
public Dog() {
// TODO Auto-generated constructor stub
}
public void meetMaster() {
// TODO Auto-generated method stub
System.out.println("聽(tīng)主人的命令");
}
public void meetEnemy() {
// TODO Auto-generated method stub
System.out.println("狂叫,并沖上去狠咬");
}
public void meetFriend() {
// TODO Auto-generated method stub
System.out.println("晃動(dòng)尾巴,表示歡迎");
}
public void meetFellow() {
// TODO Auto-generated method stub
System.out.println("嬉戲打鬧");
}
}
public class Main {
public static void main(String[] args) {
/**
* @author Administrator
* 方法一
*/
Dog dog = new Dog();
dog.meetMaster();
dog.meetEnemy();
dog.meetFriend();
dog.meetFellow();
}
}
/**
* 方法二
*/
public interface DogHabitInterface {
public void action();
}
public class DogMeetMaster implements DogHabitInterface{
@Override
public void action() {
// TODO Auto-generated method stub
System.out.println("聽(tīng)主人的命令");
}
}
public class DogMeetEnemy implements DogHabitInterface{
@Override
public void action() {
// TODO Auto-generated method stub
System.out.println("狂叫,并沖上去狠咬");
}
}
public class DogMeetFriend implements DogHabitInterface{
@Override
public void action() {
// TODO Auto-generated method stub
System.out.println("晃動(dòng)尾巴,表示歡迎");
}
}
public class DogMeetFellow implements DogHabitInterface{
@Override
public void action() {
// TODO Auto-generated method stub
System.out.println("嬉戲打鬧");
}
}
public class Main {
public static void main(String[] args) {
/**
* 方法二
*/
action(new DogMeetMaster());
action(new DogMeetEnemy());
action(new DogMeetFriend());
action(new DogMeetFellow());
}
static void action(DogHabitInterface dog){
dog.action();
}
}
微信投票第三方平臺(tái)
合肥雅美居裝修公司怎么樣
北京八維空間移動(dòng)科技有限公司怎么樣
香港電臺(tái)的旗下業(yè)務(wù)
深圳萬(wàn)太電器有限公司怎么樣
多重隨機(jī)標(biāo)簽