add syntax of inheritance to article (#23396)
* add syntax of inheritance to article add the simple syntax of inheritance before the actual example . * Fixed formatting
This commit is contained in:
@ -20,6 +20,19 @@ Java inheritance refers to the ability of a Java Class to `inherit` the properti
|
|||||||
|
|
||||||
Thus, inheritance gives Java the cool capability of _re-using_ code, or sharing code between classes!
|
Thus, inheritance gives Java the cool capability of _re-using_ code, or sharing code between classes!
|
||||||
|
|
||||||
|
## Syntax
|
||||||
|
```java
|
||||||
|
class Subclass-name extends Superclass-name
|
||||||
|
{
|
||||||
|
//methods and fields
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The extends keyword indicates that you are making a new class that derives from an existing class. The meaning of "extends" is to increase the functionality.
|
||||||
|
|
||||||
|
In the terminology of Java, a class which is inherited is called a parent or superclass, and the new class is called child or subclass.
|
||||||
|
|
||||||
|
|
||||||
Let's describe it with the classic example of a `Vehicle` class and a `Car` class :
|
Let's describe it with the classic example of a `Vehicle` class and a `Car` class :
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
Reference in New Issue
Block a user