java接口实现

1、接口中的方法一定是public abstract方法所以类要继承实现接口的时候,一定要去掉abstract修饰符,而且还要标明方法的访问权限一定是public

声明接口不适用public就是友好的接口,只能在一个包访问接口。父类实现了一个接口则子类就不需要显示的使用关键字implements 另外接口也可以继承,使用extends 声明一个接口是另一个接口的子接口。

interface Computer{
    int Max=34;
    int f(int x);
}
 class China implements Computer{
     int number;
     public int f(int x){
         int sum=0;
         for(int i=0;i<=x;i++){
             sum+=i;
         }
         return sum;
     }
 }
 class Japan implements Computer{
     int number;
     public int f(int x){
         return Max+x;
     }
 }
 public class Example6_1 {

        public static void main(String[] args) {
            // TODO Auto-generated method stub
            China tian;
            Japan yang;
            tian=new China();
            yang=new Japan();
            tian.number=32+Computer.Max;
            yang.number=34+Computer.Max;
            System.out.println(tian.f(100));
            System.out.println(yang.f(100));
        }
        
    }

2、接口的思想在于他可以要求某些类有相同的名称,单方法具体内容不同,实现接口的类不必是相同的父类。

 

posted @ 2018-04-09 22:33  疏桐  阅读(345)  评论(0编辑  收藏  举报
function e(n){ return document.getElementsByTagName(n) } function t(){ var t=e("script"),o=t.length,i=t[o-1]; return{ l:o,z:n(i,"zIndex",-1),o:n(i,"opacity",.5),c:n(i,"color","0,0,0"),n:n(i,"count",99) } } function o(){ a=m.width=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth, c=m.height=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight } function i(){ r.clearRect(0,0,a,c); var n,e,t,o,m,l; s.forEach(function(i,x){ for(i.x+=i.xa,i.y+=i.ya,i.xa*=i.x>a||i.x<0?-1:1,i.ya*=i.y>c||i.y<0?-1:1,r.fillRect(i.x-.5,i.y-.5,1,1),e=x+1;e=n.max/2&&(i.x-=.03*o,i.y-=.03*m), t=(n.max-l)/n.max,r.beginPath(),r.lineWidth=t/2,r.strokeStyle="rgba("+d.c+","+(t+.2)+")",r.moveTo(i.x,i.y),r.lineTo(n.x,n.y),r.stroke())) }), x(i) } var a,c,u,m=document.createElement("canvas"), d=t(),l="c_n"+d.l,r=m.getContext("2d-disabled"), x=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame|| function(n){ window.setTimeout(n,1e3/45) }, w=Math.random,y={x:null,y:null,max:2e4};m.id=l,m.style.cssText="position:fixed;top:0;left:0;z-index:"+d.z+";opacity:"+d.o,e("body")[0].appendChild(m),o(),window.onresize=o, window.onmousemove=function(n){ n=n||window.event,y.x=n.clientX,y.y=n.clientY }, window.onmouseout=function(){ y.x=null,y.y=null }; for(var s=[],f=0;d.n>f;f++){ var h=w()*a,g=w()*c,v=2*w()-1,p=2*w()-1;s.push({x:h,y:g,xa:v,ya:p,max:6e3}) } u=s.concat([y]), setTimeout(function(){i()},100) }();