Creating Objects
An object is created in Java using the _______________
"new" operator
Two object references that point to the same object are sometimes called
Aliases of each other
The newly created object is set up initially by a call to a
Constructor, which is like a special method that initializes the object's data and does whatever other tasks are needed (if any) to prepare the object for use.
T or F: An object must be created when its object reference variable is declared.
False No, those can be separate activities.
T or F: A String object cannot be created with a new operator
False Sure it can, but often a string literal is all you need.
T or F: The Java keyword new is a method that can be called to create objects.
False The keyword new is an operator.
T or F: A constructor of a class has the same name as the class.
True And is called when the object is created.
T or F: Strings are the only objects in Java that have a literal representation.
True Instead of saying: String name = new String("George R. R. Martin"); Just say: String name = "George R. R. Martin";
T or F: A String method can be called through a string literal.
True This is fine since a string literal represents the object.
T or F: Following a null reference will cause an exception to be thrown.
True When in doubt, check.
A constructor has the same name as the
class
After the new object is created, its address is stored in
the object reference variable