-
-
Notifications
You must be signed in to change notification settings - Fork 309
Conversation
@@ -0,0 +1,168 @@ | |||
# Java Inheritance | |||
|
|||
Java inheritance refers to the ability of a Java Class to _inherit_ the properties from some other Class. Think of it like a child inheriting properties from its parents, the concept is very similar to that. In Java lingo, it is also called _extend_-ing a class. Some simple things to remember : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Java Class to
inheritinherit
@theflametrooper might wanna take a look for typos and all. Technically, this article is correct and code snippets work the way they are supposed to, as described in the article. @koustuvsinha can't thank you enough! |
* The Class that extends or inherits is called **subclass** | ||
* The Class that is being extended or inherited is called **superclass** | ||
|
||
Thus, inheritance gives Java the cool capability of _re-using_ a code, or share code between classes! Let's describe it with the classic example of a `Vehicle` class and a `Car` class : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-using a code re-using code
@alayek @theflametrooper updated the typos & implemented suggestions |
} | ||
``` | ||
|
||
Remember, if the superclass does not have any constructors defined, you dont have to call it explicitely in the subclass. Java handles that internally for you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@koustuvsinha Also, invocation to super
constructor is done in the case when the super class is to be called with any other constructor other than the default constructor.
* The Class that is being extended or inherited is called **superclass** | ||
|
||
Thus, inheritance gives Java the cool capability of _re-using_ code, or share code between classes! Let's describe it with the classic example of a `Vehicle` class and a `Car` class : | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@koustuvsinha Add a heading 2 break point here for our sweet heart 💟 @camperbot to extract up to this point for gitter chat.
Like this,
## (just add a space after the two ##)
Move the line Let's describe it with the classic example of a
Vehicleclass and a
Carclass :
after the heading.
|
||
public class Car extends Vehicle { | ||
public Car() { | ||
super(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the extra indentation?
LGTM 👍 |
|
||
If no other constructors are defined, then Java invokes the default super class constructor (*even if not defined explicitly*). | ||
|
||
Congrats, now you know all about Inheritance! Read more about advanced ways to inherit things in [Abstract Classes]() and [Interfaces]()! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these placeholder links? Loos that way, just want to confirm. If they are, you should add the relative link that you think you would be using. When merged it will just try to create the new article but it will help you remember what to name them or give others an idea of what to name it.
* Add Java Inheritance wiki * Update article with suggestions * Implement suggestions * Minor edits * Update with new suggestions * Updated with new suggestions * Add relative links
Added Inheritance article as per #534. Please have a look @alayek , @Rafase282, @abhisekp