Example Wrapper

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

No. The only wrapper classes that exist are the eight classes in the table, one per each of the eight primitive types.

Example Wrapper

Here is a program that creates two wrapper objects, then prints out the values they hold. There is no reason to use wrapper objects in this program. Sensible uses for them will occur later in these chapters.

class WrapperDemo
{
  public static void main ( String[] args )
  {
    Integer value = new Integer( 103 );    // hold the value 103 
                                           // inside an Integer object
    Double dvalue = new Double( -32.78 );  // hold a double precision 
                                           // value inside a Double object
    
    System.out.println( "Integer object holds: " + value );
    System.out.println( "Double  object holds: " + dvalue );    
  }
}

QUESTION 19:

Was an import statement needed in this program?