HR자바 Java Method Overriding

개요[ | ]

HR자바 Java Method Overriding
해커랭크 Java
# 문제 비고
HR자바 Object Oriented Programming e
43 HR자바 Java Inheritance I
44 HR자바 Java Inheritance II
45 HR자바 Java Abstract Class
46 HR자바 Java Interface
47 HR자바 Java Method Overriding
48 HR자바 Java Method Overriding 2 (Super Keyword)
49 HR자바 Java Instanceof keyword
50 HR자바 Java Iterator

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";
    }
    // Write your overridden getNumberOfTeamMembers method here
    @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();
	}
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}