biryu2205 / Biryu

0 stars 0 forks source link

Hackerrank Java Method Override #78

Closed biryu2205 closed 6 years ago

biryu2205 commented 7 years ago
class Sports {
  String getName() {
    return "Generic Sports";
  }

  void getNumberOfTeamMembers() {
    System.out.println("Each team has n players in " + getName());
  }
}

class Soccer extends Sports {
  @Override
  String getName() {
    return "Soccer Class";
  }

  @Override
  void getNumberOfTeamMembers() {
    System.out.println("Each team has 11 players in " + getName());
  }
}

public class Solution {
  public static void main(String[] args) {
    Sports c1 = new Sports();
    Soccer c2 = new Soccer();
    System.out.println(c1.getName());
    c1.getNumberOfTeamMembers();
    System.out.println(c2.getName());
    c2.getNumberOfTeamMembers();
  }
}