java on the use of abstract classes and interfaces exploration

This article, written somewhat abstract classes and interfaces to understand, but it is a bit confusing for the use of children
if you can blurt out the following three questions, explain your level is very solid, do not read
1, the interface can be inherited interfaces ?
2, abstract class can implement interfaces do?
3, the difference between abstract classes and interfaces?

The first two answers are yes
this article theory less, are exploring the use of the code is that you can not use standard red, red is the standard error

interface

Interface inheritance, no problem
Here Insert Picture Description
inherited class, an error (as an abstract class)
Here Insert Picture Description
multiple inheritance interfaces, there is no problem
Here Insert Picture Description
implementing the interface, error
Here Insert Picture Description
static method interface must have a body
Here Insert Picture Description

Summary: The interface can extend even more than extend the interface, but can not extend classes and interfaces implent

Explanation: The interface itself is no method body, so no matter how inheritance interfaces are empty, there is no problem, but the need to implement specific method body, so you can not use

Abstract class

An abstract class can not abstract methods
Here Insert Picture Description

Abstract class without abstract methods can instantiate
Here Insert Picture Description
abstract class contains abstract methods need to override all the abstract methods to remove the abstract keyword to instantiate the
Here Insert Picture Description
subclass of abstract class must override abstract methods, if the child class is abstract, it is not heavy write
Here Insert Picture Description

An abstract class can be the same as the general category, extend the abstract class, implement interfaces, and calling the main function
Here Insert Picture Description

Summary: An abstract class without abstract methods can also be instantiated and inherits classes and implement interfaces, but if there is an abstract class abstract method, either instantiated or inherited, must be rewritten as an ordinary method

Published 106 original articles · won praise 89 · views 60000 +

Guess you like

Origin blog.csdn.net/qq_37465638/article/details/100892120
Recommended