Leave a Reply 3

Your email address will not be published. Required fields are marked *


Sucuk

Sucuk

D. p is unreachable

renko

renko

Answer is indeed correct.
The reason is that the calculation (line 2) is done outside the if-block and there are the variables b, h and p not initialized.
package q050;

public class Triangle {
static double area;
int b = 2, h = 3;

public static void main(String[] args) {
double p, b, h; //line
if (area == 0) {
b = 3;
h = 4;
p = 0.5;
}
area = p * b * h; //line 2
System.out.println(“Area is “+ area);
}
}
Output:
Exception in thread “main” java.lang.Error: Unresolved compilation problems:
The local variable p may not have been initialized
The local variable b may not have been initialized
The local variable h may not have been initialized

at q050.Triangle.main(Triangle.java:14)