java基础概念整理(三)

1、对象的上转型

    对象的上转型不能调用和使用子类对象新增的成员和变量,不能调用子类新增的方法。   

  上转型对象可以访问子类继承或者隐藏的成员变量,也可以调用子类继承或者子类重写的实例方法。因此如果子类重写了父类的某个实例方法后,当对象的上转型对象调用这个实例方法时一定是调用了子类重新写的实例方法。

2、抽象方法

 对于abstract方法,只允许声明,不允许实现,不允许使用final和abstract同时修饰一个方法或者一个类,abstract方法只能是实例方法,abstract类中可以有abstract方法。非abstract类中不可以有abstract方法。

3、面向对象编程,经常会使用到abstract类,abstract类只关心操作,不关系这些操作的具体实现的细节问题,

package com.Example1;

public class Exmaple5_12 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        MobileTelephone telephone = new MobileTelephone();
        SIM sim = new SIMofChinaMobile();
        sim.setNumber("2454545");
        telephone.userSIM(sim);
        telephone.showMessage();
        sim = new SIMofChinaUnicon();
        sim.setNumber("454664646");
        telephone.userSIM(sim);
        telephone.showMessage();

    }

}

abstract class SIM {
    public abstract void setNumber(String n);

    public abstract String giveNumber();

    public abstract String giveCorpName();
}

class MobileTelephone {
    SIM card;

    public void userSIM(SIM card) {
        this.card = card;
    }

    public void showMessage() {
        System.out.println("use card name is" + card.giveCorpName());
        System.out.println("SIm'number is" + card.giveNumber());
    }
}

class SIMofChinaMobile extends SIM {
    String number;

    @Override
    public void setNumber(String n) {
        // TODO Auto-generated method stub
        number = n;

    }

    @Override
    public String giveNumber() {
        // TODO Auto-generated method stub
        return number;
    }

    @Override
    public String giveCorpName() {
        // TODO Auto-generated method stub
        return "联通卡";
    }

}

class SIMofChinaUnicon extends SIM {
    String number;

    @Override
    public void setNumber(String n) {
        // TODO Auto-generated method stub
        number = n;

    }

    @Override
    public String giveNumber() {
        // TODO Auto-generated method stub
        return number;
    }

    @Override
    public String giveCorpName() {
        // TODO Auto-generated method stub
        return "中国移动";
    }

}

4、继承是一种已有的类创建新的类的机制,利用继承,可以创建一个共有的属性的一般类,根据一般类创建据用特殊属性的新类。

    

posted @ 2018-08-01 22:22  疏桐  阅读(185)  评论(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) }();