We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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";
}
Scanner sc = new Scanner(System.in);
class Sports{
String getname(){
return "Generic Sports";
}
public void getNumberofTeamMembers(){
System.out.println("Each team has n players in" + getName());
}
class Soccer1 extends Sports{
@Override
String getname(){
return "Soccer class";
}
public 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();
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Method Overriding
You are viewing a single comment's thread. Return to all comments →
import java.util.*; class Sports{
}
class Soccer extends Sports{ @Override String getName(){ return "Soccer Class"; } Scanner sc = new Scanner(System.in);
}
public class Solution{
}