Java Basic Learning Content 6 (Inheritance / Abstract Class / Interface)

Inheritance

Define a new class based on the existing class. (Original class = superclass, newly defined class = subclass At this time, the methods and fields of the superclass are inherited.

Inheritance


class SubClass extends SuperClass {
  ...
}

Subclasses can be overridden to override the superclass method processing

override


class SubClass extends SupreClass {
  @Override methodA() {
    super.methodA(); //Execute processing of existing method
    ...
  }
}

The following conditions must be met in order to override. -The method name and arguments are the same. -The return value must be the same as the original method or a subclass -The access modifier is the same as or wider than the original method. -The method must not have the final modifier.

Abstract class

A class that contains methods that do not define what to do.

Abstract class


abstract class AbsClass {
  public abstract void methodA();
}

interface

A class that defines the methods that need to be implemented.

Interface


public interface InterfaceSampl(){
  public abstract void methodA();
  default void methodB(){
    ...
  }
}

Recommended Posts

Java Basic Learning Content 6 (Inheritance / Abstract Class / Interface)
Advanced inheritance abstract, interface -java
Java basic learning content 7 (exception)
JAVA learning history interface inheritance
Java basic learning content 5 (modifier)
Java learning memo (abstract class)
Java Basic Learning Content 8 (Java API)
Java basic learning content 4 (repetition)
Java basic learning content 3 (operator / ternary operator)
Java basic learning content 9 (lambda expression)
Java basic learning content 2 (array / ArrayList)
[Java] Class inheritance
java (abstract class)
[java] abstract class
Java basic learning content 1 (literals, variables, constants)
abstract (abstract class) and interface (interface)
JAVA learning history interface
Java learning memo (basic)
Java learning memo (interface)
Java learning memo (inheritance)
About java abstract class
Interface / abstract class / override
Use of Abstract Class and Interface properly in Java
[Java] What is class inheritance?
Difference between interface and abstract class
[JAVA] Difference between abstract and interface
Java learning (0)
java (interface)
[Java] Inheritance
Java inheritance
[Java] Inheritance and structure of HttpServlet class
[java] interface
Java inheritance
Proper use of interface and abstract class
JAVA learning history abstract classes and methods
java (inheritance)
[ev3 × Java] Interface, implementation and inheritance (event handling)
Java and Swift comparison (3) Class implementation / Class inheritance / Class design
Why java allows final class A {abstract class B {}}
About Java interface
Java class methods
java Scanner class
For JAVA learning (2018-03-16-01)
Java learning day 5
Java HashMap class
Java basic grammar
Java basic grammar
About class inheritance.
interface and abstract
Java basic knowledge 1
[Java] Nested class
Java anonymous class
[Java] Basic structure
Ruby Learning # 33 Inheritance
[Java] [Basic] Glossary
[Java] About interface
About Java class
Java basic grammar
Java basic grammar
[Java] Functional interface
About java inheritance