1)接口是对abstract类的进行一步扩展
2)接口中定义的方法全部是未实现的,(类似于抽象方法),目的是在实现接口的类之间建立一种协议,
3)接口中的变量都是常量
4)接口是一种特殊的类,
成员变量必须是常量
成员方法必须是抽象方法
如下:
package study_interface;
public interface Study_three {
/* 接口中的成员变量不能修改 */
public static final String car_color="red";
public static final int car_weight= 200;
public void impressColor();
public void impressWeight();
}
package study_interface;
public class Car implements Study_three {
String color;
int weight;
Car(String color, int weight){
this.color =color;
this.weight = weight;
}
public void impressColor() {
// TODO Auto-generated method stub
System.out.print(color);
}
@Override
public void impressWeight() {
// TODO Auto-generated method stub
System.out.print(weight);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Car("red",100).impressColor();
new Car("yellow",200).impressWeight();
}
}
想要使用父类的方法就要使用super关键字