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.
Java Method Overriding
Java Method Overriding
Sort by
recency
|
130 Discussions
|
Please Login in order to post a comment
Static, private, and final methods cannot be overridden because they are bound at compile time. Betbhai9 Signup
import java.io.; import java.util.;
public class Solution {
my code:
import java.io.; import java.util.;
class Sports{ String getName(){ return "Generic Sports"; }
} 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 {
}
class Sports{
}
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{
}
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); }