/* Variables3.java CIS 160 David Klick 2015-09-02 Demonstration of using reference variables. */ public class Variables3 { public static void main(String[] args) { // Variables can also refer to objects. They are called reference variables. // Objects are not one of the eight built-in data types. // String objects are one of the most commonly used objects in Java. // We still have to declare and initialize a reference variable before we use it. // Declare and initialize a few reference variables Object obj = new Object(); // Object is the data type, obj is the variable name // Strings are so commonly used that Java allows you to omit the "new String()" // bit when creating them. The two lines below are equivalent. String str1 = new String("Hello, world!"); String str2 = "Hello, world!"; // You can use System.out to display objects (sort of) System.out.println(obj); System.out.println(str1); System.out.println(str2); } } /* You should see something like this when the program is run: java.lang.Object@15db9742 Hello, world! Hello, world! */