zoukankan      html  css  js  c++  java
  • java学习47天2020/8/21

    public interface fish {
    	String name="asd" ;
    	int age=0;
    	int velocity=2;
    	static void show()
    	{
    		System.out.println("Fish"+", "+name+", "+age+", "+velocity);
        }
    
    }
    
    public interface beast{
    	String name1="asd" ;
    	int age1=0;
    	int appetite=2;
    	public default void show()
    	{
    		System.out.println("beast"+", "+name1+", "+age1+", "+appetite);
    	}
    }
    
    public class amphibious implements fish,beast{
    	public void show()
    	{
    		System.out.println("Fish"+", "+name+", "+age+", "+velocity);
    		System.out.println("beast"+", "+name1+", "+age1+", "+appetite);
    	 }
    	public static void main(String []args)
    	{
    		amphibious m=new amphibious();
    		m.show();
    	}
    	
    
    }
    

     接口中的方法都是抽象方法,所以 public abstract 可以省略不写,所有的变量都是常量,必须赋值,默认public  abstract  final int a=0;

    接口之间可以多继承,一个类可以实现那个多个接口,接口还有一个功能是用来解耦合,接口是一个特殊的抽象类,接口之间的所有访问修饰符都是public ,所有的方法都是抽象方法,所有的变量都是常量;

    一个类实现了一个接口,必须实现接口内的所有方法;

    二.能不能在用接口来继承接口,接口实现多重继承不太方便

    构造函数不能实现

    三。例题

  • 相关阅读:
    50个网页常用小代码
    web前端题目(持续更新)
    一步步构建大型网站架构(转)
    CentOS下配置node.js
    ajax文件上传
    test
    文件上传input简便美化方案
    String.match()与RegExp.exec()
    ie7下zindex问题
    javascript将数组插入到另一个数组中
  • 原文地址:https://www.cnblogs.com/qiangini/p/13583402.html
Copyright © 2011-2022 走看看