Use of Abstract Class and Interface properly in Java

Abstract Class and Interface Review

List of things you can't do

Abstract Class Interface
Can be defined? No (Can be a mold) No
field popular? Yes No(Can but force public static final)
Method private/public/protected Forced public
Inheritance Only one super class Any number is OK

Proper use of Abstract Class and Interface

Use Abstract Class if:

--When you want to share an abstract class between similar classes. --When a class inherited from an abstract class has similar methods and fields. --Non-static When using non-final fields.

Use Interface if:

--When an unrelated class defines this interface (for example, Comparable). ――When you don't know who defines it, or when you don't care. --When you want to inherit multiple times.

Reference Abstract Methods and Classes from Oracle

Recommended Posts

Use of Abstract Class and Interface properly in Java
Proper use of interface and abstract class
abstract (abstract class) and interface (interface)
Handling of date and time in Ruby. Use Date and Time properly.
Difference between interface and abstract class
StringBuffer and StringBuilder Class in Java
[JAVA] Difference between abstract and interface
Implement Java Interface in JRuby class and call it from Java
[Java8] Proper use of Comparable and Comparator in terms of employee sorting
java (abstract class)
interface and abstract
[Java] Inheritance and structure of HttpServlet class
Mechanism and characteristics of Collection implementation class often used in Java
[Java / Swift] Comparison of Java Interface and Swift Protocol
[java] abstract class
[Java] Contents of Collection interface and List interface
Discrimination of Enums in Java 7 and above
Java Basic Learning Content 6 (Inheritance / Abstract Class / Interface)
[Java] How to use FileReader class and BufferedReader class
[Java] Use of final in local variable declaration
A quick review of Java learned in class
Why use setters/getters instead of public/private in Java
Use Shift Right and Shift Left properly in Selenium
[Java] How to use Calendar class and Date class
Use of Date class
Callable Interface in Java
Use OpenCV in Java
Use PreparedStatement in Java
About java abstract class
Interface / abstract class / override
[Java] How to use compareTo method of Date class
Use of Japanese fonts and external characters in JasperReport
A quick review of Java learned in class part4
Browse class objects in Kotlin (instead of Java class name.class)
[JAVA] What is the difference between interface and abstract? ?? ??
Use variables for class and id names in haml
A quick review of Java learned in class part2
[Java] Handling of character strings (String class and StringBuilder class)
Summarize the additional elements of the Optional class in Java 9
Advanced inheritance abstract, interface -java
Example of using abstract class
How to use java class
[Java] Comparator of Collection class
Java class definition and instantiation
[Java] Use Big Decimal properly ~ 2018 ~
Java learning memo (abstract class)
Summary of "abstract interface differences"
Summary of Java Math class
Advantages and disadvantages of Java
Use Redis Stream in Java
About abstract classes in java
Implementation of tri-tree in Java
Java abstract methods and classes
[For beginners] Explanation of classes, instances, and statics in Java
Implement Thread in Java and try using anonymous class, lambda
[Java] Set structure of collection class (about HashSet and TreeSet)
How to call and use API in Java (Spring Boot)
Reasons to use Servlet and JSP separately in Java development
Define abstract methods in Java enum and write each behavior
[Java] I thought about the merits and uses of "interface"
Access the network interface in Java