X Tutup
Skip to content

Commit d34cb20

Browse files
ErikSchierboommirkoperillo
authored andcommitted
inheritance - replace about.md file with concept files
* Pre-populate inheritance concept's about.md file from after.md file * Pre-populate inheritance concept's links.json file from after.md file * inheritance - Remove after.md document
1 parent a7cf840 commit d34cb20

File tree

3 files changed

+62
-58
lines changed

3 files changed

+62
-58
lines changed

concepts/inheritance/about.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,56 @@
1-
TODO: add information on inheritance concept
1+
## Inheritance
2+
3+
Java supports inheritance as it's core functionality and then to achieve a lot of OOPs principles like abstraction using
4+
inheritance.
5+
6+
A class can extend another class using `extends` keyword and can inherit from an interface using `implements` keywords.
7+
8+
## Access Modifiers
9+
10+
The access modifiers define rules for the member variables of a class about their access from another classes(or anywhere in
11+
the code).
12+
13+
There are mainly three access modifiers:
14+
15+
- private
16+
- public
17+
- protected
18+
- Default (No keyword required)
19+
20+
You can read more about them [here][access-modifiers]
21+
22+
## Inheritance vs Composition
23+
24+
These concepts are very similar and are often confused.
25+
26+
- Inheritance means that the child has IS-A relationship with the parent class.
27+
28+
```java
29+
interface Animal() {
30+
public void bark();
31+
}
32+
33+
class Dog implements Animal {
34+
public void bark() {
35+
System.out.println("Bark");
36+
}
37+
}
38+
```
39+
40+
Here, `Dog` IS-A `Animal`
41+
42+
- Composition represents a HAS-A relationship.
43+
44+
```java
45+
interface Engine {
46+
47+
}
48+
49+
class Car {
50+
private Engine engine;
51+
}
52+
```
53+
54+
Here, `Car` HAS-A `Engine`
55+
56+
[access-modifiers]: https://www.geeksforgeeks.org/access-modifiers-java/

concepts/inheritance/links.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
[]
1+
[
2+
{
3+
"url": "https://www.geeksforgeeks.org/access-modifiers-java/",
4+
"description": "access-modifiers"
5+
}
6+
]

exercises/concept/inheritance/.docs/after.md

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)
X Tutup