Consider the following code segment: String word = new String("question"); What does this code segment do?
Declares and initializes an object of the String class.
Consider the following code example: Scanner scan = new Scanner(System.in); Which of the following sentences best describes the features in this code segment?
Variable scan points to an object, Scanner is the class of this object.
Which of the following is a class in Java?
String
What keyword do we use to tell Java to set aside memory to create an object?
new
Which of these code segments shows a constructor being used to create a new object?
RegularPolygon p = new RegularPolygon(2, 2.5);
Which of the following creates a rectangle with length and width equal to 2.0?
Rectangle r = new Rectangle(2.0); Rectangle r = new Rectangle(2.0, 2.0);
Which of the following will be printed by the following code? RegularPolygon shape = new RegularPolygon(5.0);System.out.println(shape);
equilateral triangle with side length 5.0
Which of the following statements about overloaded constructors is true?
Constructors for a class can be overloaded but they must all have a different number of parameters, different order of parameters or different types of parameters.
Which of the following best describes what happens when the code segment below is run? RegularPolygon p = new RegularPolygon(); System.out.println(p);
"equilateral triangle with side length 1.0" is printed
Which of the following best describes what happens when the code segment below is run? RegularPolygon p = new RegularPolygon(5.5); System.out.println(p);
"equilateral triangle with side length 5.5" is printed