-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaInheritance1.java
More file actions
52 lines (44 loc) · 1004 Bytes
/
JavaInheritance1.java
File metadata and controls
52 lines (44 loc) · 1004 Bytes
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
/**
* CONCEPT: Inheritance (IS-A Relationship)
* ---------------------------------------
* Inheritance is a key pillar of Object-Oriented Programming (OOP).
* It allows a subclass (Bird) to inherit the methods and fields
* of a superclass (Animal) using the 'extends' keyword.
*
* PROBLEM:
* Add a 'sing' method to the Bird class and call it in main so the
* output displays walking, flying, and singing.
*
* LINK: https://www.hackerrank.com
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class Animal{
void walk(){
System.out.println("I am walking");
}
}
class Bird extends Animal
{
void fly()
{
System.out.println("I am flying");
}
//--Start of the solution
void sing()
{
System.out.println("I am singing");
}
}
//--End of the solution
public class Solution{
public static void main(String args[]){
Bird bird = new Bird();
bird.walk();
bird.fly();
bird.sing();
}
}