HackerRank Java- Inheritance I




The code above is provided for you in your editor. You must add a sing method to the Bird class, then modify the main method accordingly so that the code prints the following lines:

I am walking
I am flying
I am singing



  1. import java.io.*;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.math.*;
  5. import java.util.regex.*;
  6. class Animal{
  7. void walk(){
  8. System.out.println("I am walking");
  9. }
  10. }
  11. class Bird extends Animal {
  12. void fly() {
  13. System.out.println("I am flying");
  14. }
  15. void sing() {
  16. System.out.println("I am singing");
  17. }
  18. }
  19. public class Solution{
  20. public static void main(String args[]){
  21. Bird bird = new Bird();
  22. bird.walk();
  23. bird.fly();
  24. bird.sing();
  25. }
  26. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube