001    /**
002     * Exercise 5.6 from the book.
003     * 
004     * @author Kristian Torp, torp (at) cs (dot) aau (dot) dk
005     * @version 1.0
006     */
007    public class Exercise5_6 {
008            // instance variables
009            public int publicI;
010    
011            protected int protectedI;
012    
013            private int privateI;
014    
015            int friendlyI;
016    
017            /**
018             * Constructor for objects of class Exercise5_6
019             */
020            public Exercise5_6() {
021                    publicI = 10;
022                    protectedI = 20;
023                    privateI = 30;
024                    friendlyI = 40;
025            }
026    
027            /**
028             * Shows all public instance variables
029             */
030            public void showPublic() {
031                    System.out.println("publicI: " + publicI);
032            }
033    
034            protected void showProtected() {
035                    System.out.println("protectedI: " + protectedI);
036            }
037    
038            private void showPrivate() {
039                    System.out.println("privateI: " + privateI);
040            }
041    
042            void showFriendly() {
043                    System.out.println("friendlyI: " + friendlyI);
044            }
045    
046            /**
047             * Main which some objects
048             */
049            public static void main(String args[]) {
050                    Exercise5_6 c1 = new Exercise5_6();
051                    c1.showPublic();
052                    c1.showProtected();
053                    c1.showPrivate();
054                    c1.showFriendly();
055    
056                    c1.publicI = 11;
057                    c1.showPublic();
058                    c1.protectedI = 21;
059                    c1.showProtected();
060                    c1.privateI = 31;
061                    c1.showPrivate();
062                    c1.friendlyI = 41;
063                    c1.showFriendly();
064            }
065    }