Call the super method in Java


From simple things, I will output java steadily. I am studying with the goal of passing java silver.

What is super

Used when referencing superclass instances and variables.

How to call a parent class method using super

super. method name

I will write

//Super class
class hoge {
	public void print() {
		System.out.println("hello from superclass");

//Child class
class huga extends hoge {
	public void print() {
		System.out.println("hello from child class");

	public void executePrint() {
		//Child class print
		//Superclass print

public class Main {
	public static void main(String[] args) {
		huga obj = new huga();

Execution result

hello from child class
hello from superclass

You can see that the method of the parent class can be explicitly called from the child class.

in conclusion

In the case of a constructor, if you instantiate a child class Superclass constructor Child class constructor is executed.

Details will be written in another article.


This article was written with reference to the following information.

-Oracle Certification Textbook Java Programmer Silver SE11

Recommended Posts

Call the super method in Java
Call Java method from JavaScript executed in Java
Call the Windows Notification API in Java
What is the main method in Java?
[Java] Handling of JavaBeans in the method chain
Java method call from RPG (method call in own class)
How to mock a super method call in PowerMock
How to get the class name / method name running in Java
Access the network interface in Java
I translated [Clone method for Java arrays] as the Clone method in Java arrays.
Guess the character code in Java
Java method
java (method)
Automatic photo resizing method in Java
Specify the java location in eclipse.ini
[Android, Java] Convenient method to calculate the difference in days
Read CSV in Java (Super CSV Annotation)
Java comparison using the compareTo () method
Unzip the zip file in Java
Create a method to return the tax rate in Java
Parsing the COTOHA API in Java
[Java] method
[Java] method
Sample code to call the Yahoo! Local Search API in Java
My thoughts on the equals method (Java)
Get the result of POST in Java
Try using the Stream API in Java
Concurrency Method in Java with basic example
I tried the new era in Java
[Java] How to use the toString () method
[Java] Use cryptography in the standard library
Organized memo in the head (Java --Array)
Try calling the CORBA service in Java 11+
How to get the date in java
The story of writing Java in Emacs
Console input in Java (understanding the mechanism)
Call Visual Recognition in Watson Java SDK
Element operation method in appium TIPS (Java)
[Java] Pass arguments to constructor in Mockito / Set method default call to callRealMethod
Partization in Java
Java8 method reference
Rock-paper-scissors in Java
[Java] forEach method
java8 method reference
Pi in Java
[Java] Random method
[Java] split method
FizzBuzz in Java
[Order method] Set the order of data in Rails
[Android] Call Kotlin's default argument method from Java
Regarding the transient modifier and serialization in Java
The story of low-level string comparison in Java
About the confusion seen in startup Java servers
The story of making ordinary Othello in Java
About the idea of anonymous classes in Java
ChatWork4j for using the ChatWork API in Java
A story about the JDK in the Java 11 era
The order of Java method modifiers is fixed
The intersection type introduced in Java 10 is amazing (?)
The story of learning Java in the first programming
Feel the passage of time even in Java