current position:Home>Javase basic interview questions

Javase basic interview questions

2022-01-26 22:22:59 Everything goes with fate ~~~

Interface

  1. Special class file

  2. effect :1. Specify the rules 2. Reduce coupling

  3. Usage rule :

    • The default attributes in the interface are Static constant properties (public static final).

    • Methods in interfaces are abstract ==(public abstract), If you need to define the implementation of a specific method , At this point, the method needs to use default== modification .

    • The access permission of the method in the interface cannot be private.

    • Multiple inheritance can be realized between interfaces , But interfaces cannot implement each other .

    • There is no constructor in the interface , therefore Interface cannot be instantiated .

abstract class

  1. Abstract classes are created by abstract modification .

  2. effect : Reduce the implementation difficulty between interface implementation classes and interfaces .

    The implementation class does not necessarily need to use all the methods defined in the interface , You can create an abstract class and implement some methods first , Leave the methods needed to implement the class , The implementation class then inherits the abstract class , Implement the required methods .

  3. Usage rule :

    • Abstract classes can name abstract methods , You can also generate specific methods .

    • Abstract methods of abstract class names must be overridden by subclasses .

    • When an abstract class implements an interface , Interface methods can not be overridden .

    • There are construction methods in abstract classes , But it can't be used .

copyright notice
author[Everything goes with fate ~~~],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262222583512.html

Random recommended