Of the following, which would be considered the no-arg constructor for the rectangle class?
The JavaTM Tutorial
Trail: Learning the Java Language Lesson: Object Basics and Simple Data Objects As you know, a class Declaring a Variable to Refer to an ObjectFrom the Variables Instantiating a ClassThe new operator instantiates a class by allocating memory for a new object. Initializing an ObjectHere's the code for the Point class:public class Point { public int x = 0; public int y = 0; //A constructor! public Point(int x, int y) { this.x = x; this.y = y; } }This class contains a single constructor. You can recognize a constructor because it has the same name as the class and has no return type. The constructor in the Point class takes two integer arguments, as declared by the code (int x, int y). The following statement provides 23 and 94 as values for those arguments:Point originOne = new Point(23, 94);The effect of the previous line of code can be illustrated in the next figure:
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved. When a method's return type is an object what is actually returned to the calling program?When a method's return type is an object, what is actually returned to the calling program? only one copy of the field in memory.
Which of the following method is a type of constructor and is always called when an object is created?constructors. Classes can have special methods called constructors. A constructor is a method that is automatically called when an object is created.
When you write an enumerated type declaration you are actually creating a special kind of?An enumerated data type is actually a special type of class. nested class.
What happens when this keyword is used in a constructor's body to call another constructor of the same class if that call is not the first statement in the constructor?no-argument constructor. 8.5 Q4: What happens when this is used in a constructor's body to call another constructor of the same class if that call is not the first statement in the constructor? a. a. A compilation error occurs.
|