1.接口
1. 接口的由来:为了体现事物功能的扩展性,Java通过接口来定义这些额外的扩展功能。但是并不给出具体实现,需要类来重写 2. 接口的特点 (1)定义接口:interface 定义格式:interface 接口名{} (2)实现类:implements 定义格式:class 类名 implements 接口名{} (3)接口不能实例化,需要按照多态的方式实例化 (4)接口的实现类:具体类,类中需要重写接口中所有抽象方法
public class TestDemo01 {
public static void main(String[] args) {
rInterface rf1 = new EZ();
rf1.R(); //精准弹幕
System.out.println("==============");
rInterface rf2 = new Gragas();
rf2.R(); //肉弹冲击
}
}
interface RInterface{
public abstract void R();
}
class EZ implements RInterface{
String name = "伊泽瑞尔";
public void attack(){
System.out.println("平A");
}
public void magic(){
System.out.println("放技能");
}
@Override
public void R() {
System.out.println("精准弹幕");
}
}
class Gragas implements RInterface{
String name = "古拉加斯";
public void attack(){
System.out.println("平A");
}
public void magic(){
System.out.println
|