Reusing code is one of the many compelling features of Java.
You can reuse code by creating a new class without having to write from scratch. The trick of this approach is to use classes without breaking existing program code. There are two ways to achieve this.
The first is very intuitive: you only need to produce an object of an existing class in the new class. Because the new class is made up of objects that have existing classes, this method is called a combination . This method simply re-uses the functionality of the existing program code, not its form.
The second method is a little more nuanced, and it creates a new class according to the type of the existing class. Instead of changing the form of an existing class, take the form of an existing class and add new code to it. This magical approach is called inheritance , and the compiler can do most of the work.
In terms of composition and inheritance, new types are generated using existing classes.
Focus on the code: toString, extends
java--multiplexing Code, composition, Inheritance (Java programming Idea)