54-183 Programming Concepts I
Course Home Page   Course Schedule Page

Using Classes Part I

  1. Creating new objects.   So far, we have used only predefined objects (like System.out), or constructed new String references by putting  string constants in double quotes ("").

  2. We need a general method for constructing new objects: So, to send a message to construct a new String reference, we would form it as String("hello world")
    Recall that a message must be sent to an object. The operator new arranges for an object to be created that can be sent the message:
    new String ("hello world")
    This returns a reference to a newly created String object that. It is necessary to save a new reference if we want to use it later on Thus, reference variables become essential.
    String s;
    s = new String ("The british are coming");
    Using s we can continue to use this newly created object:
    String upper, lower;
    upper = s.toUpperCase ();
    lower = s.toUpperCase ();
    System.out.println (s);

Based on material by: Alan Kaplan of Clemson Univesity
Revisions responsibility of Barbara Boucher Owens
Last modified:9 December 1999