001 /** 002 * Exercise 8.1 from the book. 003 * 004 * @author Kristian Torp, torp (at) cs (dot) aau (dot) dk 005 * @version 1.0 006 */ 007 public class Exercise8_1 implements TestInterface { 008 public int getX() { 009 if (x > 0) { // can see the x field 010 //x = 12; // cannot change the value of x 011 } 012 return x; 013 } 014 015 /** 016 * Main method that creates an object. 017 */ 018 public static void main(String[] args) { 019 Exercise8_1 c1 = new Exercise8_1(); 020 System.out.println(c1.getX()); 021 } 022 }