Advertisement
Guest User

Why use private modifier for immutable final instance var?

a guest
Feb 24th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. class InterfaceExample{
  2.     public static void main (String... args){
  3.         MyInterface[] = {new ImplOne, new ImplTwo};
  4.  
  5.         for (MyInterface i : iList) {
  6.             System.out.println(i.getString());
  7.         }
  8.     }
  9. }
  10.  
  11. interface MyInterface{
  12.     public String getString();
  13. }
  14.  
  15. class ImplOne implements MyInterface{
  16.     @Override
  17.     public String getString(){ return "Who am I?"; }
  18. }
  19.  
  20. class ImplTwo implements MyInterface{
  21.     @Override
  22.     public String getString(){ return "I am YOU."; }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement