1个回答
展开全部
public class Main { //入口
public static void main(String[] args) {
DPHero ez = new DPHero();
Support qinnv = new Support();
ez.setName("伊泽瑞尔");
qinnv.setName("琴女");
}
}
***
public interface Ad { //ad接口
public void physicAttack();
}
***
public interface Ap { //ap接口
public void magicAttack();
}
***
public interface Healer { //healer接口
public void heal();
}
***
public class Hero { //hero类
private String name;
private int hp;
private int armor;
private int movespeed;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getHp() {
return hp;
}
public void setHp(int hp) {
this.hp = hp;
}
public int getArmor() {
return armor;
}
public void setArmor(int armor) {
this.armor = armor;
}
public int getMovespeed() {
return movespeed;
}
public void setMovespeed(int movespeed) {
this.movespeed = movespeed;
}
}
***
public class DPHero extends Hero implements Ad, Ap { //dphero类
@Override
public void physicAttack() {
System.out.println("可以进行物理攻击");
}
@Override
public void magicAttack() {
System.out.println("可以进行魔法攻击");
}
}
***
public class Support extends Hero implements Healer { support类
@Override
public void heal() {
System.out.println("加血");
}
public void heal(Hero hero) {
System.out.println("为"+ hero.getName() +"加血");
}
public void heal(Hero hero,int hp){
System.out.println("为"+ hero.getName() + "加"+ hp +"血");
}
}
public static void main(String[] args) {
DPHero ez = new DPHero();
Support qinnv = new Support();
ez.setName("伊泽瑞尔");
qinnv.setName("琴女");
}
}
***
public interface Ad { //ad接口
public void physicAttack();
}
***
public interface Ap { //ap接口
public void magicAttack();
}
***
public interface Healer { //healer接口
public void heal();
}
***
public class Hero { //hero类
private String name;
private int hp;
private int armor;
private int movespeed;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getHp() {
return hp;
}
public void setHp(int hp) {
this.hp = hp;
}
public int getArmor() {
return armor;
}
public void setArmor(int armor) {
this.armor = armor;
}
public int getMovespeed() {
return movespeed;
}
public void setMovespeed(int movespeed) {
this.movespeed = movespeed;
}
}
***
public class DPHero extends Hero implements Ad, Ap { //dphero类
@Override
public void physicAttack() {
System.out.println("可以进行物理攻击");
}
@Override
public void magicAttack() {
System.out.println("可以进行魔法攻击");
}
}
***
public class Support extends Hero implements Healer { support类
@Override
public void heal() {
System.out.println("加血");
}
public void heal(Hero hero) {
System.out.println("为"+ hero.getName() +"加血");
}
public void heal(Hero hero,int hp){
System.out.println("为"+ hero.getName() + "加"+ hp +"血");
}
}
追问
能否在详细的解释一下下,我这边还是有点蒙
追答
就是最基础的java继承和接口,子类继承父类的成员变量,接口声明抽象方法,一个类去实现他,然后创建实例对象使用他们的方法
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询