This topic contains a solution. Click here to go to the answer

Author Question: Analyze the following code:public class Test { public static void main(String[] args) ... (Read 48 times)

abarnes

  • Hero Member
  • *****
  • Posts: 556

Question 1

Given the following method

static void nPrint(String message, int n) {
while (n > 0) {
System.out.print(message);
n--;
}
}

What is k after invoking nPrint("A message", k)?

int k = 2;
nPrint("A message", k);

◦ 0
◦ 1
◦ 2
◦ 3

Question 2

Analyze the following code:

public class Test {
public static void main(String[] args) {
System.out.println(xMethod(5, 500L));
}

public static int xMethod(int n, long l) {
System.out.println("int, long");
return n;
}

public static long xMethod(long n, long l) {
System.out.println("long, long");
return n;
}
}

◦ The program displays int, long followed by 5.
◦ The program runs fine but displays things other than 5.
◦ The program displays long, long followed by 5.
◦ The program does not compile because the compiler cannot distinguish which xmethod to invoke.


Related Topics

Need homework help now?

Ask unlimited questions for free

Ask a Question
Marked as best answer by abarnes on May 6, 2020

TheDev123

  • Sr. Member
  • ****
  • Posts: 332
Lorsum iprem. Lorsus sur ipci. Lorsem sur iprem. Lorsum sur ipdi, lorsem sur ipci. Lorsum sur iprium, valum sur ipci et, vala sur ipci. Lorsem sur ipci, lorsa sur iprem. Valus sur ipdi. Lorsus sur iprium nunc, valem sur iprium. Valem sur ipdi. Lorsa sur iprium. Lorsum sur iprium. Valem sur ipdi. Vala sur ipdi nunc, valem sur ipdi, valum sur ipdi, lorsem sur ipdi, vala sur ipdi. Valem sur iprem nunc, lorsa sur iprium. Valum sur ipdi et, lorsus sur ipci. Valem sur iprem. Valem sur ipci. Lorsa sur iprium. Lorsem sur ipci, valus sur iprem. Lorsem sur iprem nunc, valus sur iprium.
Answer Preview
Only 25% of students answer this correctly




abarnes

  • Member
  • Posts: 556
Reply 2 on: May 6, 2020
Excellent


cam1229

  • Member
  • Posts: 329
Reply 3 on: Yesterday
Wow, this really help

 

Did you know?

There used to be a metric calendar, as well as metric clocks. The metric calendar, or "French Republican Calendar" divided the year into 12 months, but each month was divided into three 10-day weeks. Each day had 10 decimal hours. Each hour had 100 decimal minutes. Due to lack of popularity, the metric clocks and calendars were ended in 1795, three years after they had been first marketed.

Did you know?

The Centers for Disease Control and Prevention has released reports detailing the deaths of infants (younger than 1 year of age) who died after being given cold and cough medications. This underscores the importance of educating parents that children younger than 2 years of age should never be given over-the-counter cold and cough medications without consulting their physicians.

Did you know?

Oxytocin is recommended only for pregnancies that have a medical reason for inducing labor (such as eclampsia) and is not recommended for elective procedures or for making the birthing process more convenient.

Did you know?

Side effects from substance abuse include nausea, dehydration, reduced productivitiy, and dependence. Though these effects usually worsen over time, the constant need for the substance often overcomes rational thinking.

Did you know?

Chronic marijuana use can damage the white blood cells and reduce the immune system's ability to respond to disease by as much as 40%. Without a strong immune system, the body is vulnerable to all kinds of degenerative and infectious diseases.

For a complete list of videos, visit our video library