subject

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.
B. 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.
D. 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?
A. The private variables hourlyRate and hoursWorked should have been declared public .
B. The private method calculateEarning should have been declared public.
C. The variable earnings in the calculateEarnings method is a local variable.
E. The variables hourlyRate and hoursWorked in the calculateEarnings method are local variables.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 17:00
1. so if i wanted to build a linux server for web services(apache) with 1cpu and 2 gb of memory.-operating at 75% of memory capacity2. a windows server with 2 cpu/ 4gb memory- operating at 85% of memory capacity3. a storage server with 1 cpu/ 2gb memory- operating at 85% of memory capacityhow much memory do i have to add for each server.so that the utilization rate for both cpu and memory is at a baseline of 60%."the details for the cpu like its processor or the memory's speed isnt to be concerned" yeah i kept asking my teacher if he's even sure about the but the whole class seems to be confused and the project is due in 3 days..this is a virtualization project where i have to virtualize a typical server into an exsi hypervisor.
Answers: 2
question
Computers and Technology, 22.06.2019 23:30
What does 21 pilots middle aged name as a band 15 years prior to them naming their band 21 pilots?
Answers: 1
question
Computers and Technology, 23.06.2019 03:50
Q-1 which of the following can exist as cloud-based it resources? a. physical serverb. virtual serverc. software programd. network device
Answers: 1
question
Computers and Technology, 24.06.2019 00:00
Afashion designer wants to increase awareness about her brand. which network can she use and why she can use the blank to blank her products online. answers for the first blank: internet, extranet, or intranet answers for the second blank: market, design, and export
Answers: 1
You know the right answer?
Consider the following class definition. public class Element
{
public static int max_v...
Questions
question
Computers and Technology, 30.09.2021 19:00
question
Social Studies, 30.09.2021 19:00
question
Computers and Technology, 30.09.2021 19:00
Questions on the website: 13722362