[java] abstract class

In the last article, I talked about interfaces. https://qiita.com/QiitaD/items/835ed6ee4e52cb6b214a This time, I will describe "abstract classes" that are often compared with interfaces.

What is an abstract class?

A class that has one or more abstract methods. Abstract methods must be implemented in subclasses, so you can force developers to override them.

Treatment

There are the following rules for handling abstract classes.

  1. Cannot be instantiated
  2. Must override abstract method
  3. It is necessary to describe the constructor in the subclass.

Differences from the interface

The following is a table of the differences.

Abstract class interface
Method with implementation Can be implemented Cannot be implemented
Member variables Class member variables constant
Multiple inheritance Impossible Yes

Implementation

Can be implemented as follows

 //抽象クラスViecleの実装
abstract class Viecle {
 //抽象メソッド
}

Subclasses can be implemented by inheriting abstract classes.

 //抽象クラスViecleの実装
abstract class Car extends Vielce {
 //スーパークラスのコンストラクタ呼び出し
 //抽象メソッドのオーバーライド
}

Recommended Posts

java (abstract class)
[java] abstract class
About java abstract class
Java learning memo (abstract class)
Java class methods
[Java] Class inheritance
Java HashMap class
[Java] Nested class
Java anonymous class
About Java class
[Java] Object class
Java local class
Java abstract modifier [Note]
About class division (Java)
About Java StringBuilder class
[Java] About Singleton Class
abstract (abstract class) and interface (interface)
Java inner class review
Java programming (class method)
About Java String class
Java programming (class structure)
Interface / abstract class / override
Java Basic Learning Content 6 (Inheritance / Abstract Class / Interface)
Why java allows final class A {abstract class B {}}
[Java] Integer wrapper class reference
Advanced inheritance abstract, interface -java
Java memo (standard class) substring
Java tips --StaticUtility class modifier
Java inflexible String class substring
Java memo (standard class) length
Example of using abstract class
How to use java class
[Java] Comparator of Collection class
Java class definition and instantiation
Java
Summary of Java Math class
[Java] What is class inheritance?
About Java class variables class methods
Use of Abstract Class and Interface properly in Java
About abstract classes in java
Java
Java abstract methods and classes
Why implement an abstract class (Abstract)
[Java basics] What is Class?
Create an immutable class with JAVA
Why are class variables needed? [Java]
Difference between interface and abstract class
Call Kotlin's sealed class from Java
Java, abstract classes starting from beginners
[Java] Object-oriented syntax --class method / argument
Various methods of Java String class
[Java] Memo for naming class names
How to disassemble Java class files
Kotlin Class to send to Java developers
StringBuffer and StringBuilder Class in Java
How to decompile java class files
[Java] How to use LinkedHashMap class
[JAVA] Difference between abstract and interface
java (use class type for field)
Java source code reading java.lang.Math class
[Java] Button template class by Graphics