PDA

View Full Version : Java - Hide a code?


zk0
12-14-2006, 08:44 PM
If I want to hide a code that generates a random number:

int secretNumber = (int) (Math.random() * 101);

Do I make it like this:

private int secretNumber = (int) (Math.random() * 101);

Thanks for any advice!

PremiumBlend
12-14-2006, 08:48 PM
Is this an abstract class? If not, in the constructor put your code:

this.secretNumber = (int)(Math.random() * 101);

If this is an abstract class, create a static method such as:


public static int getRandom() {
return new Integer(Math.random() * 101);
}