You are here: Home / Topics / Page / 5

Program to use Boolean Wrapper class in Java

Filed under: Java
// Program to use Boolean Wrapper classclass  WrapperBoolean{public static void main( String args[ ] ){ Boolean b1 = new Boolean(false); Boolean b2 = new Boolean("true"); System.out.println(b1.booleanValue()); System.out.println(b2.booleanValue());}}Output:falsetrue

Program to use Simple Wrapper Class in Java

Filed under: Java
//  Program to use Simple Wrapper Class.class  Wrapper1{public static void main( String args[ ] ){ // Boxing Integer  iOb = new Integer(100); // Unboxing int i = iOb.intValue(); System.out.println(i + " : " + iOb); }}Output:100 : 100

Program to use enum in an application in Java

Filed under: Java
//  Program to use enum in an application.import java.util.Random;enum  Answers {NO, YES, MAYBE, LATER, SOON, NEVER}class Question {Random rand = new Random();Answers ask() { int prob = (int) (100 * rand.nextDouble()); if (prob < 15)  return Answers.MAYBE;