abstract class extends
Abstract method:abstract void fun()
An abstract class is abstract
a class decorated with. Because there are no concretely implemented methods in an abstract class, it cannot be instantiated; an abstract class does not necessarily contain abstract methods;
abstract class fun{
abstract void fun();
}
important point:
- The abstract method must be
public
either orprotected
(becauseprivate
it cannot be implemented if it is a subclass); - If a class inherits from an abstract class, the subclass must implement the abstract method of the superclass. If the subclass does not implement the abstract method of the superclass, the subclass must also be defined as an abstract class;
- Abstract classes cannot create objects.
interface implements
An interface is an abstraction of behavior, and an interface can contain methods and variables. The variable must be public static final
decorated with; the method must be public abstract
decorated with.
interface fun(){}
Difference between abstract class and interface
- Variable: any type (abstract class) /
public static final
(interface) - Method: any type - abstract method, method (abstract class)/
public abstract
(interface) - An abstract class is an abstraction of things, an interface is an abstraction of a behavior