Consider the following class definition.
public class Element
{
public sta...
Computers and Technology, 05.01.2022 04:10 linnybear300
Consider the following class definition.
public class Element
{
public static int max_value = 0;
private int value;
public Element (int v)
{
value = v;
if (value > max_value)
{
max_value = value;
}
}
}
The following code segment appears in a class other than Element.
for (int i = 0; i < 5; i++)
{
int k = (int) (Math. random() * 10 + 1);
if (k >= Element. max_value)
{
Element e = new Element(k);
}
}
Which of the following best describes the behavior of the code segment?
Exactly 5 Element objects are created.
Exactly 5 Element objects are created.
A
Exactly 10 Element objects are created.
Exactly 10 Element objects are created.
B
Between 0 and 5 Element objects are created, and Element. max_value is increased only for the first object created.
Between 0 and 5 Element objects are created, and Element. max_value is increased only for the first object created.
C
Between 1 and 5 Element objects are created, and Element. max_value is increased for every object created.
Between 1 and 5 Element objects are created, and Element. max_value is increased for every object created.
D
Between 1 and 5 Element objects are created, and Element. max_value is increased for at least one object created.
Between 1 and 5 Element objects are created, and Element. max_value is increased for at least one object created.
E
The class Worker is defined below. The class includes the method getEarnings, which is intended to return the total amount earned by the worker.
public class Worker
{
private double hourlyRate;
private double hoursWorked;
private double earnings;
public Worker(double rate, double hours)
{
hourlyRate = rate;
hoursWorked = hours;
}
private void calculateEarnings()
{
double earnings = 0.0;
earnings += hourlyRate * hoursWorked;
}
public double getEarnings()
{
calculateEarnings();
return earnings;
}
}
The following code segment appears in a method in a class other than Worker. The code segment is intended to print the value 800.0, but instead prints a different value because of an error in the Worker class.
Worker bob = new Worker(20.0, 40.0);
System. out. println(bob. getEarnings());
Which of the following best explains why an incorrect value is printed?
The private variables hourlyRate and hoursWorked are not properly initialized.
The private variables hourlyRate and hoursWorked are not properly initialized.
A
The private variables hourlyRate and hoursWorked should have been declared public .
B
The private method calculateEarnings should have been declared public.
The private method calculateEarnings should have been declared public .
C
The variable earnings in the calculateEarnings method is a local variable.
The variables hourlyRate and hoursWorked in the calculateEarnings method are local variables.
E The variables hourlyRate and hoursWorked in the calculateEarnings method are local variables.
Answers: 2
Computers and Technology, 22.06.2019 20:40
Assume that there is a 4% rate of disk drive failure in a year. a. if all your computer data is stored on a hard disk drive with a copy stored on a second hard disk drive, what is the probability that during a year, you can avoid catastrophe with at least one working drive? b. if copies of all your computer data are stored on three independent hard disk drives, what is the probability that during a year, you can avoid catastrophe with at least one working drive?
Answers: 1
Computers and Technology, 22.06.2019 21:30
After you clean an engine with hot water spray, it seems to stall; when it doesn't stall, it's idling noisily. technician a says to check for loose bolts on the flex plate near the torque converter. technician b says to wipe down the spark plug wires and the distributor cap. who is correct? a. technician a b. both technicians a and b c. technician b
Answers: 1
Computers and Technology, 23.06.2019 17:00
What does the faves button do? a. users mark a web page as a favorite b. leads other readers to favor a specific page c. readers sort and align their favicons, or favorite icons d. leads users to a message board where they can post questions
Answers: 1
Computers and Technology, 23.06.2019 17:00
The more powerful, 60 volt cables and the main power shut off on an hev are both colored orange
Answers: 1
Biology, 05.05.2020 08:56
Mathematics, 05.05.2020 08:56
Mathematics, 05.05.2020 08:56
Mathematics, 05.05.2020 08:56
Physics, 05.05.2020 08:56
Mathematics, 05.05.2020 08:56
History, 05.05.2020 08:56
Mathematics, 05.05.2020 08:56
Mathematics, 05.05.2020 08:56
Physics, 05.05.2020 08:56
Mathematics, 05.05.2020 08:56