[JAVA] abstract (abstract class) and interface (interface)

What is abstract (abstract class)?

A class that has one or more abstract methods.

** Abstract method ** is a method that declares only the definition of arguments and method names without describing specific processing.

Abstract class declaration.java


abstract class class name{}

Abstract method declaration.java


abstract Return type Method name(Argument type Argument name);

Feature

⭕️ Superclass methods can be ** overridden ** (rewritten) in subclasses.

❌ Cannot inherit multiple classes.

❌ Cannot be instantiated directly.

What is an interface?

A variable and method type defined without describing the specific processing of the method included in the class.

Interface declaration.java


interface Interface name{}

Interface implementation.java


class class name implements interface name{}

Feature

⭕️ Only the method type can be described first, and the process can be described immediately before use.

⭕️ Multiple inheritance of the interface is OK.

image

Abstract class

Son Goku (super class) can take over the surname of Son to multiple names of Son Gohan (subclass) and Son Goten (subclass).

Also, if Gohan becomes a son, the surname will be rewritten to Suzuki (override).

Interface

Gohan can take over the specifications of Goku to Saiyan and Chichi to Earthling.

A clear gene can be determined immediately before.

Recommended Posts

abstract (abstract class) and interface (interface)
interface and abstract
Difference between interface and abstract class
Interface / abstract class / override
Proper use of interface and abstract class
Use of Abstract Class and Interface properly in Java
[JAVA] Difference between abstract and interface
Class and model
java (abstract class)
[java] abstract class
Inheritance and interface.
Java Basic Learning Content 6 (Inheritance / Abstract Class / Interface)
Class and instant part2
About java abstract class
[JAVA] What is the difference between interface and abstract? ?? ??
Advanced inheritance abstract, interface -java
java.util.Optional class and null and not null
Example of using abstract class
Java class definition and instantiation
Java learning memo (abstract class)
Difference between class and instance
Summary of "abstract interface differences"
Relationship between package and class
Java abstract methods and classes
Why implement an abstract class (Abstract)
Implement Java Interface in JRuby class and call it from Java
Difference between instance method and class method
Get TypeElement and TypeMirror from Class
interface
Difference between instance variable and class variable
Flowing interface trial and error memo
StringBuffer and StringBuilder Class in Java
Internal class and lambda study notes
Differences between Applet class and JApplet class
[Java] Differences between instance variables and class variables
[Java] Inheritance and structure of HttpServlet class
[Java / Swift] Comparison of Java Interface and Swift Protocol
JAVA learning history abstract classes and methods
Java programming (static clauses and "class variables")
[Details] Let's master abstract classes and interfaces! !!
[Java] Contents of Collection interface and List interface
I want to recursively get the superclass and interface of a certain class