Reference An Object

Once an object has been created, you can:

To access an object properties or methods you reference it using the dot syntax which is the object name followed by a property or method name:

INSIDE of a class, you can simply use the name of the property (field). For example, to print out the width and height of the Box object we created earlier, you can use:

System.out.println(“Box width is: “ + width  + “, Box height is: “ + height);

OUTSIDE of a class; however, you need to use the object.property syntax:

MyBox.height;

However, if a reference is made to an object that was created inside a class, you still have to give it an object reference:

System.out.println(“Width of Triangle is: “ + myTriangle.width);