Sitemap

Thursday, June 25, 2015

Java: Interfaces


public interface Language {
    String getBirthday();

    String getGreeting();
}

public class Indonesian implements Language {
    public String getBirthday() {
        return "Selamat Ulang Tahun";
    }

    public String getGreeting() {
        return "Apa kabar?";
    }
}

public class English implements Language {
    public String getBirthday() {
        return "Happy Birthday";
    }

    public String getGreeting() {
        return "How are you?";
    }
}

public class LanguageDemo {
    public static void main(String[] args) {
        Language language = new English();
        System.out.println(language.getBirthday());
        System.out.println(language.getGreeting());

        language = new Indonesian();
        System.out.println(language.getBirthday());
        System.out.println(language.getGreeting());
    }
}



OUTPUT:
Happy Birthday
How are you?
Selamat Ulang Tahun
Apa kabar?


No comments:

Post a Comment