JAVA语言 - 接口 (26)

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关键字

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值