Sort by

recency

|

130 Discussions

|

  • + 0 comments

    Static, private, and final methods cannot be overridden because they are bound at compile time. Betbhai9 Signup

  • + 0 comments

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
     Sports spo = new Sports();
     Sports soc = new Soccer();
     System.out.println(spo.getName());
     spo.getNumberOfTeamMembers();
     System.out.println(soc.getName());
     soc.getNumberOfTeamMembers();
     }}
     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());
       } 
    
     }
    
  • + 0 comments

    my code:

    import java.io.; import java.util.;

    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) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Sports sp = new Sports();
        System.out.println(sp.getName());
        sp.getNumberOfTeamMembers();
    
        Sports mysp = new Soccer();
        System.out.println(mysp.getName());
        mysp.getNumberOfTeamMembers();
    
    }
    

    }

  • + 0 comments

    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();
    }
    

    }

  • + 0 comments

    You can also follow this approach using String.format @Override void getNumberOfTeamMembers(){ int n=11; String result = String.format( "Each team has %d players in %s",n,getName() ); System.out.println(result); }