About inheritance (Java Silver)

I'm trying to summarize the parts that are not well understood in the basics of Java for the acquisition of Java Silver.


I think I understand the concept of inheritance itself. Personally, I think it's easier to understand if you express it as extending the function rather than inheriting it. The image of a subclass is that the superclass has a higher degree of abstraction and fewer functions, and more specific functions have been added to make it a superclass + α (extension).

・ Super class


class SuperA {}

-Subclass that inherits the superclass


class SubA extends SuperA {}

Things impossible

--Multiple superclasses cannot be specified after extends.


class SubA extends SuperA, SuperB {}

--Private members defined in the superclass cannot be used in the subclass.

Members defined in the superclass can be used in the subclass, but private members can only be used from the same class, so they cannot be used in the subclass.

--When overriding a method, the access modifier must be within the public range specified in the superclass.

For example, if you want to override a method that specifies public in a superclass, you must specify public. (The disclosure range cannot be narrowed.)

-Public range of access modifiers

wide narrow
public protected Default private
Accessable from any class Subclass or same package Same package Same class only

--Members with the final qualifier cannot be overridden.

Reference type type conversion

There are two types of type conversion in superclasses and subclasses:

--Implicit type conversion Subclass → Superclass Implementation class → Interface

--Type conversion by cast Subclass ← Superclass Implementation class ← Interface

In other words, is it an image that implicit type conversion can be done if the functions that can be used after conversion are not reduced?


--Members called when overriding

When a subclass object is assigned to a superclass type variable, the members of the superclass are called except for the instance method.

Recommended Posts

About inheritance (Java Silver)
About java inheritance
Java inheritance
java (inheritance)
[Java] About interface
About Java class
About Java arrays
About interface, java interface
Study Java Silver 1
About java var
About Java literals
About Java commands
About Java String class
About Java access modifiers
About encapsulation and inheritance
About Java lambda expressions
About Java entry points
About Java 10 Docker support
Personal summary about Java
Java8 Silver exam memorandum
All about Java programming
[Java] Implicit inheritance memo
Java learning memo (inheritance)
About java abstract class
[Java Silver] (Exception handling) About try-catch-finally and try-with-resource statements
[Experience] Passed Java SE 8 Silver
Java SE8 Silver Pass Experience
Java starting from beginner, inheritance
What I researched about Java 7
About Alibaba Java Coding Guidelines
[Java] What is class inheritance?
java (inheritance of is-a principle)
About Java class variables class methods
About Java Packages and imports
About abstract classes in java
[Java Silver] Array generation method
What I researched about Java 5
I'm not sure about Java Servlet
About =
About Eclipse environment (Java, Liberty, JavaScript)
About object-oriented inheritance and about yield Ruby
How to pass Oracle Java Silver
About file copy processing in Java
About Java primitive types and reference types
What I learned with Java Silver
Diary for Java SE 8 Silver qualification
What I researched about Java learning
[For Java beginners] About exception handling
This and that about Base64 (Java)
[Qualification] Java Silver SE11 Passing Experience
About Records preview added in Java JDK 14
[About JDBC that connects Java and SQL]
Inexperienced learning methods to get Java Silver 11
[Java beginner] About initialization of multidimensional array
[Basic knowledge of Java] About type conversion
Continued Talk about writing Java in Emacs @ 2018
The story received by Java SE11 silver