Why is inheritance useful in Java

Inheritance explained simply

JAVA TUTORIAL

Inheritance is a powerful concept with which we can better structure and extend our programs. Learn everything about the topic here. Fun with polymorphism included!

The extends keyword
The keyword super ()
  • super () explicitly calls the constructor of the immediate superclass.
  • In the case of constructors without parameters, super () is automatically added by the compiler.

go to: constructor on inheritance

  • All Java classes automatically inherit from Object.
  • The Object class provides useful methods for our classes.

go to: The class Object

  • The comparison operator == tests whether two variables point to the same object.
  • The equals () method is used to compare objects according to their content. However, this must still be overwritten accordingly.

go to: compare objects

go to: toString () overwrite

Everything for Inheritance in Java

Inheritance clearly explained

Inheritance is a powerful concept with which we can better structure and extend our programs. We explain it here simply and precisely.

Inheritance constructors

In this chapter we want to dig a little deeper into the subject of inheritance and deal with constructors in connection with inheritance.

The protected access modifier

There are four different levels of access to class members in Java. "Protected" access, which is defined with the protected modifier, is particularly important for inheritance.

Abstract classes and methods

We use the abstract keyword to create abstract classes and methods. For a mature class design, this is unreliable. Here you will learn exactly how the concept of abstract codes works.

Polymorphism in Java

Polymorphism allows us to write very flexible and powerful code. Mastering the rules of polymorphism is an essential skill for every Java developer.

Typecast

If you want to use polymorphism sensibly in Java, you can't avoid the topic of type conversion. We'll teach you the most important things in this chapter. You will also find out what exactly is to be converted here.

The class Object

All classes go back to a top super class. This "ancestor" is appropriately called Object. So reason enough to take a closer look at the super class of everything.

toString () method

The Java.lang.Object class provides a method called toString () which, when called, returns a string representation of the current object. How exactly we deal with the toString () method is shown here.

Compare objects

When are two objects "the same"? This (seemingly banal) question always creates confusion. Learn more about it here.

What is an interface?

Multiple inheritance is not allowed in Java. But from this apparent weakness Java gains one of its greatest strengths.

JAVA blog

The default method in interfaces
An interface can only have abstract or static methods? This rule no longer applies since Java 8!
Category: JAVA | Date: 07/10/2019

Access levels when overwriting methods
In this blog post we look at a special case and explain the interaction between the access levels and the overwriting of methods.
Category: JAVA | Date: 06/22/2019

Difference between explicit and implicit casting
We regularly need type conversion (casting) for both primitive and complex data types. But what is the difference between implicit and explicit casting?
Category: JAVA | Date: 07/10/2019

Browse multidimensional arrays
How do you search a multidimensional array for a specific element? We will now look at two specific examples for Java.
Category: JAVA | Date: 03/01/2019

The default method in interfaces
An interface can only have abstract or static methods? This rule no longer applies since Java 8!
Category: JAVA | Date: 07/10/2019

Access levels when overwriting methods
In this blog post we look at a special case and explain the interaction between the access levels and the overwriting of methods.
Category: JAVA | Date: 06/22/2019

Difference between explicit and implicit casting
We regularly need type conversion (casting) for both primitive and complex data types. But what is the difference between implicit and explicit casting?
Category: JAVA | Date: 07/10/2019

Browse multidimensional arrays
How do you search a multidimensional array for a specific element? We will now look at two specific examples for Java.
Category: JAVA | Date: 03/01/2019

Java tutorial Chapter overview

Static elements

Use static variables and methods

Primitive data types

By the end of the chapter you will know how to use primitive data types correctly.

Arrays in Java

Arrays allow data to be stored in a higher-level data structure