-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance.java
More file actions
105 lines (84 loc) · 3.47 KB
/
Inheritance.java
File metadata and controls
105 lines (84 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//Inheritance = One class property share to another class Is called Inheritance
//Types:
// 1.Single-Level Inheritance
// class Shape {
// public void show() {
// System.out.println("Shape name displays here");
// }
// }
// class Triangle extends Shape {
// public void can() {
// System.out.println("Triangle");
// }
// public static void main(String... s) {
// Triangle t = new Triangle();
// t.show();
// t.can();
// }
// }
//2.Multi-level Inheritance:- Means multple level of inheritance we see here like 1 is parent of 2
// and 2 is parent of 3 ,3 is parent of 4
// class Geometry { //Great-Grand-father
// public void geometry() {
// System.out.println("It comprises of various shapes and formulas");
// }
// }
// class Shapes extends Geometry { //Grand-Father
// public void shapes() {
// System.out.println("Geometry Stores multiple shapes");
// }
// }
// class Triangle extends Shapes { //Father
// public void trngle() {
// System.out.println("Triangle is one of the Shape that present in Geometry");
// }
// }
// class Equilateraltriangle extends Triangle { //Child
// public void eql() {
// System.out.println("Equilateral-triangle is one of the form of triangle also called Shape that present in Geometry ");
// }
// public static void main(String[] args) {
// Equilateraltriangle et = new Equilateraltriangle();
// et.geometry();
// et.shapes();
// et.trngle();
// et.eql();
// }
// }
//3.Hierarchical Inheritance = One Parent class and many child class
// class Shape {
// public void show() {
// System.out.println("Shapes:");
// }
// }
// class Circle extends Shape {
// public void can() {
// System.out.println("Round in shape");
// }
// }
// class Square extends Shape {
// public void man() {
// System.out.println("Square in shape");
// }
// }
// class Triangle extends Shape {
// public void ran() {
// System.out.println("3 edges shape");
// }
// public static void main(String[] args) {
// Circle c = new Circle(); //Object make that call
// c.can(); //method of inherited class
// c.show(); //method of parent class
// Square s = new Square();
// s.show();
// s.man();
// Triangle t = new Triangle();
// t.show();
// t.ran();
// }
// }
//4.Hybrid-Inheritance:- In this type all the types of inheritance we see in same like single,multilevel,hierarchical
//5.Multiple Inheritance:- It is not present in java in the form of classes but we can achieve it by Interfaces
//(In this we have multiple parent classes that inherit by a single child class)
// - ❌ class Child extends Parent1, Parent2 → Not allowed in Java.
// - ✅ class Child implements Interface1, Interface2 → Perfectly valid.