Java abstract methods and classes

Details undecided method

For example, suppose you have a car or bicycle method. All vehicles have the ability to "run". Even programmatically, all classes that inherit from the Vehicle class should have a run method. Therefore, normally, the run method should be defined in the Vehicle class and inherited, but since the driving method is different for each vehicle, the processing content cannot be defined in the Vehicle class.

Abstract method

To define a method whose processing is undecided, you can define a method called an abstract method by adding "abstract" to the beginning of the method. Do not write ** content processing ** in the abstract method. "Abstract" means "abstract". It is called an "abstract method" because it is an unfinished method for which no specific processing has been decided. An abstract method will result in an error if the subclass has not overridden the method. So you can force a subclass to override that method and define what it does. If you want your subclass to always have a method, define it as an abstract method in your superclass.

Abstract class

A class that has at least one abstract method is called an "abstract class" and is prefixed with "abstract". Abstract classes cannot instantiate. A class with an incomplete method called an abstract method is also incomplete. You cannot instantiate an unfinished class. [Example]

abstract class SuperClass {  //Abstract class definition
  abstract public void hello();  //Definition of abstract method

Recommended Posts

Java abstract methods and classes
JAVA learning history abstract classes and methods
[Java] Generics classes and generics methods
Java generics (defines classes and methods)
Java programming (classes and instances, main methods)
java (classes and instances)
[Java] Personal summary of classes and methods (basic)
(Note) Java classes / variables / methods
Java methods and method overloads
[Ruby] Singular methods and singular classes
About abstract classes in java
Ruby methods and classes (basic)
[Ruby] Singular methods and singular classes
Java methods
About Java static and non-static methods
Java, abstract classes starting from beginners
How to call classes and methods
[JAVA] Difference between abstract and interface
Studying Java 8 (StaticIF and Default methods)
Classes and instances Java for beginners
Define abstract methods in Java enum and write each behavior
Classes and instances
interface and abstract
Functions and methods
Java and JavaScript
XXE and Java
[Details] Let's master abstract classes and interfaces! !!
[java] abstract class
[Java ~ Classes and External Libraries ~] Study Memo (6)
A note on the differences between interfaces and abstract classes in Java
Effective Java 3rd Edition Chapter 4 Classes and Interfaces
Understand the difference between abstract classes and interfaces!
Differences in writing Java, C # and Javascript classes
Kantai Collection Java # 1 Classes and Objects [For Beginners]
Check static and public behavior in Java methods
How to access Java Private methods and fields
Java abstract modifier [Note]
[Ruby] Classes and instances
Getters and setters (Java)
java classes, instances, objects
[Java] Thread and Runnable
HashMap and HashSet classes
About classes and instances
abstract (abstract class) and interface (interface)
Ruby classes and instances
Java --Serialization and Deserialization
[Java] Arguments and parameters
Ruby variables and methods
timedatectl and Java TimeZone
[Java] Branch and repeat
List and happy classes
[Java] Variables and types
About java abstract class
[Java] Overload and override
[JAVA] What is the difference between interface and abstract? ?? ??
Java classes and instances to understand in the figure
Use of Abstract Class and Interface properly in Java
Equivalence comparison of Java wrapper classes and primitive types
[Java] [javaSliver] The interface and abstract classes are complicated, so I will summarize them.
Advanced inheritance abstract, interface -java
[For beginners] Explanation of classes, instances, and statics in Java