<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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.