Chapter 9 - Implementing Classes and using Objects
Which of the following best describes what happens?
A. sum becomes 1/2; f1 and f2 remain unchanged
What is displayed when the following code fragment is compiled/executed?
B. 2000
What happen if you forget to initialize a field that is an object and start calling its methods?
B. A run-time "null reference exception" error is reported
Which of the following is the appropriate name for a constructor in the class Flower?
B. Flower
Who invented Java?
B. James Gosling
The class Animal has a constructor that takes one int parameter. Which of the following is a valid statement that declares and creates an instance of an Animal in a program?
C. Animal elephant = new Animal (10);
Why doesn't Java let you create an object of the math class
C. B/C all Math;s methods and fields are static. so all math objects would be identical
Which of the following is NOT a good reason for making a class's field static?
C. The field is used to count the number of times any of the methods of a particular object are called
Which of the following statements would be illegal on someFun's body?
D. All of the above would be legal
What is called a client of a class x?
D. Any class that invokes X's constructors and/or calls its methods
What are overloaded methods?
D. Methods of the same class that have the same name but different numbers or types of parameters
A public method converToCm converts a person's height in feet and inches into centimeters and returns the result. Which of the following is the appropriate header for this method?
D. public int convertToCm(int feet, int inches)