JAVA (inherited characteristics)

1, the characteristics of inheritance in Java classes

  • Java supports only single inheritance, do not support multiple inheritance. (A son can have only one father)

    • Some languages ​​support multiple inheritance, format: extends Class 1, Class 2, ...

  • Java supports multiple inheritance (inheritance system)

 

2, inherited features of Java classes

  • If you want to use all the features of this system is to create objects with the bottom of the class (DemoC)

  • If you want to see common features of this system, look at the top-level category (DemoA)

 

3, demo


 

class Demo2_Extends {

    public static void main(String[] args) {

        DemoC d = new DemoC();

        d.show();

    }

}



class DemoA {

    public void show() {

        System.out.println("DemoA");

    }

}





class DemoB extends DemoA {

    public void method() {

        System.out.println("DemoB");

    }

}





class DemoC extends DemoB {

    public void print() {

        System.out.println("DemoC");

    }

}

 

 

 

Guess you like

Origin blog.csdn.net/Cricket_7/article/details/92060838