File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
Object Oriented Programming/L3 - Inheritance Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ class Animal {
2+ public void eat (){
3+ System .out .println ("Eating" );
4+ }
5+ }
6+
7+ class Dog extends Animal {
8+ public void bark (){
9+ System .out .println ("Barking" );
10+ }
11+ }
12+
13+ class Cat extends Animal {
14+ public void meow (){
15+ System .out .println ("Meowing" );
16+ }
17+ }
18+
19+ class hierarchialinheritance {
20+ public static void main (String [] args ){
21+ Cat yu = new Cat ();
22+ yu .eat ();
23+ yu .meow ();
24+ //yu.bark(); // Compile Time Error
25+ }
26+ }
Original file line number Diff line number Diff line change @@ -135,5 +135,30 @@ Weeping<br>
135135When two or more classes inherits a single class is called Hierarchial Inheritance.
136136
137137```
138+ class Animal{
139+ public void eat(){
140+ System.out.println("Eating");
141+ }
142+ }
138143
144+ class Dog extends Animal{
145+ public void bark(){
146+ System.out.println("Barking");
147+ }
148+ }
149+
150+ class Cat extends Animal{
151+ public void meow(){
152+ System.out.println("Meowing");
153+ }
154+ }
155+
156+ class hierarchialinheritance{
157+ public static void main(String[] args){
158+ Cat yu = new Cat();
159+ yu.eat();
160+ yu.meow();
161+ //yu.bark(); // Compile Time Error
162+ }
163+ }
139164```
You can’t perform that action at this time.
0 commit comments