![]() |
Using Objects, Part I |
|||||||||||
| System.out.print ("Hello");
System.out.print ("World"); |
Hello World |
| System.out.println ("Hello");
System.out.println ("World"); |
Hello
World |
System.out.print ("CLEMSON!");
car54.ask ("Where are my fish?");
smart.get ();
x.y ("a", "b");

If we can have references to String objects, what behaviors does the String class provide?
The above message does not change "sc", rather it creates a reference to a new String object that contains "SC"."sc".toUpperCase()
Let's look at the methods we know so far:
| Class | Method | Return value | Arguments |
| PrintStream | println | none | none |
| PrintStream | println | none | String reference |
| PrintStream | none | String reference | |
| String | toUpperCase | String reference | none |
System.out.println (chant);
System.out.println (chant);
System.out.println (chant);
System.out.println ("Go, go, go!!");
Because chant is a String
reference, we can even send it messages, e.g.,
System.out.println (chant.toUpperCase ());
If you do not declare a variable, but use it in your program, an error will be issued at compile time.String chant; PrintStream output;
To give a variable a value, we use an assignment statement:
We can then use chant as we did above.chant = "Go tigers, go!"
The general form of an assignment statement is:
variable = valueSome other examples of assignment and use:
| Assignment | Use |
| output = System.out | output.println ("Hello"); |
| loudChant = chant.toUpperCase (); | output.println (loudChant); |