Question
11. If the value of f(x, y, z) is always an integer, which of the following conditions ensures that the loop below terminates? while (f(x,
11. If the value of f(x, y, z) is always an integer, which of the following conditions ensures that the loop below terminates?
while (f(x, y, z) < 100) { }
Question 11 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
12. The following program segment is intended to sum a[0] through a[n-1], where n = a.length: sum = 0; i = 0; n = a.length; while (i != n) { i++; sum += a[i]; }
In order for this segment to perform as intended, which of the following modifications, if any, should be made?
Question 12 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
13. What is the output of the following program?
int sum = 0, k, val = 1; for (k = 0; k <= 8; k++) { sum += val; val++; } System.out.println(sum);
Question 13 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
14. How can you identify a constructor in a class file?
I. The name of the constructor is the same as the name of the class. II. The name of the constructor is the same as the name of the file (without .java). III. The constructor looks like a method, but it has no return type (not even void).
Question 14 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
When is it not necessary to invoke method myMethod using dot notation?
Question 15 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
16. What is a mutator method?
Question 16 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
17. What is the output of the following code? ArrayList
Question 17 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
| ||
|
|
18. public class WeatherSnapshot
{ private int tempInFahrenheit; private int humidity; // value of 56 means 56% humidity private int dewpoint; // in degrees Fahrenheit private Date date; // uses a Date object to store the date private int time; // in military time, such as 1430 = 2:30 pm private boolean cloudy; // true if 25% or more of the sky is covered // constructor not shown, but it initializes all instance variables // postcondition: returns temperature public int getTemp() { return tempInFahrenheit; } // postcondition: returns date public Date getDate() { return date; } // postcondition: returns true if precipitation is likely; false otherwise public boolean precipitationLikely() { // implementation not shown } // other methods not shown }
Which of the following is a class constructor? I. getTemp II. precipitationLikely III. WeatherSnapshot
Question 18 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
19. Consider the following class designed to store weather statistics at a particular date and time.
public class WeatherSnapshot { private int tempInFahrenheit; private int humidity; // value of 56 means 56% humidity private int dewpoint; // in degrees Fahrenheit private Date date; // uses a Date object to store the date private int time; // in military time, such as 1430 = 2:30 pm private boolean cloudy; // true if 25% or more of the sky is covered // constructor not shown, but it initializes all instance variables // postcondition: returns temperature public int getTemp() { return tempInFahrenheit; } // postcondition: returns date public Date getDate() { return date; } // postcondition: returns true if precipitation is likely; false otherwise public boolean precipitationLikely() { // implementation not shown } // other methods not shown }
Suppose a WeatherSnapshot object named currentWeather has been correctly instantiated in a client class. Which of the following will correctly call the precipitationLikely method?
Question 19 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started