Topics to cover Instance variables vs. local variables
A new method in the Person class public String predictFuture () { int magicNumber = (int) (Math.random() * 4 + 1); String prediction = "Yours is the life of a student"; switch(magicNumber) { case 1: prediction = "You will do well in life"; break; case 2: prediction = "You will be rich and famous"; break; case 3: prediction = "Happiness will be yours"; break; case 4: prediction = "You will be a programmer"; break; case 5: prediction = "Life is not kind"; break; } return prediction;
Local Variables Declared within the body of a method Have “local scope” Can only be used in the method in which they are declared Local variables can be declared in any block of code
Instance Variables Are declared at the start of the class definition outside of any interior block of code Are used to store the “state” of an object Can be used by any method in the class Have unique values for each object