Wellcom to my Blog for Javascript

java的多态性

class test1
{
    int a=3;
    public test1(int a)
    {
        this.a=a;
    }
    public void aa()
    {
        System.out.println("这个是父类中的方法");
    }
}
class son extends test1
{
    public son(int a)
    {
        super(a);
    }
    public void aa()
    {
        System.out.println("这个是子类的方法");
    }
    public void bb()
    {
        System.out.println("这是子类中的另一个方法");
    }
}
public class test
{
    public static void main(String []args)
    {
        test1 bb=new son(3);//调用的还是父类中的方法或属性不能够调用子类的中的补贴给你的方法
        System.out.println(bb.a);
    }
}

posted on 2014-05-12 15:05  温柔的鲨鱼  阅读(137)  评论(0编辑  收藏  举报

导航