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.

Inheritance

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

SuperA.java


class SuperA {}

-Subclass that inherits the superclass

SubA.java


class SubA extends SuperA {}

Things impossible

--Multiple superclasses cannot be specified after extends.

SubA.java


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?

Other

--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
Summarize Java inheritance (Java Silver 8)
[Java Silver] About initialization
About inheritance
[Java] Inheritance
Java inheritance
[Java Silver] About equals method
Java inheritance
java (inheritance)
About Java interface
Java Silver memo
[Java] About arrays
About class inheritance.
Something about java
Where about java
About Java features
About Ruby inheritance
About Java threads
[Java] About interface
About Java class
About Java arrays
About interface, java interface
Study Java Silver 1
About List [Java]
About java var
About Java literals
About Java commands
About Java log output
About Java functional interface
[Java] Overload / Override / Inheritance
Java, about 2D arrays
Passed Java SE8 Silver
About class division (Java)
java bronze silver passed
About [Java] [StreamAPI] allMatch ()
About Java StringBuilder class
[Java] About Singleton Class
Java Silver Study Day 1
Java Silver passing experience
[Java] About anonymous classes
About method splitting (Java)
[java] Java SE 8 Silver Note
About Java Array List
About Java Polymorphism super ()
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
[Java] About enum type
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
A note about Java GC
Advanced inheritance abstract, interface -java