Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

<tag> 1. Find Error The following class definition has an error. What is it? pub

ID: 3530567 • Letter: #

Question

<tag>

1.

Find Error

The following class definition has an error. What is it?

public class MyClass
{
private int x;
private double y;
public static void setValues(int a, double b)
{
x = a;
y = b;
}
}


2.

Find Error

Assume the following declaration exists :

enum Coffee { MEDIUM, DARK, DECAF }

Find the error(s) in the following switch statement:

// This code has errors!
Coffee myCup = DARK;
switch (myCup)
{
case Coffee.MEDIUM :
System.out.println("Mild flavor.");
break;
case Coffee.DARK :
System.out.println("Strong flavor.");
break;
case Coffee.DECAF :
System.out.println("Won

Explanation / Answer

x and y must be in static variables because they are used static in the code / method. Cannot make a static reference to the non-static field x. change modifier of x and y to 'static.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote