I had a fellow student ask me this question and I have no idea how to answer it.
The following code works fine.
int x = 40;
int y = 35;
if (x > y)
{
int ans = x + y;
}
However, the code below gives an error saying that the variable declaration isn't allowed where it is. Why isn't it allowed there? NetBeans throws the following exception: Uncompilable source code - Erroneous tree type:
int x = 40;
int y = 35;
if (x > y)
int ans = x + y;
We are using NetBeans 8.0 Beta if it matters.