Question: Consider the following program, and the resulting error messages that occur when the program gets compiled using the javac command. In 1 or 2 simple

Consider the following program, and the resulting error messages that occur
when the program gets compiled using the javac command. In 1 or 2 simple
English sentences, explain why the error messages occurred:
// This program does not compile. How come?
class BadExample
{
public static void main (String [] args)
{
int x =3;
int y =7;
computeSum();
}
static void computeSum()
{
int sum = x + y;
System.out.println("sum ="+ sum);
}
}
Here is what was output after we attempted to compile this program:
BadExample.java:12: error: cannot find symbol
int sum = x + y;
^
symbol: variable x
location: class BadExample
BadExample.java:12: error: cannot find symbol
int sum = x + y;
^
symbol: variable y
location: class BadExample
2 errors

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!