Code:
public Test
{
public static void main(String[] args)
{
if(true)
int a=10;
System.out.println("Hello");
}
}
Output: Compile-time error: Variable declaration not allowed here.
Explanation: If we are not using curly bracket then only one statement allows for if statement but that statement should not be declarative statement; In above example we are declaring int variable without curly bracket, this is not allowed because int a = 10 is a declarative statement. We can use any other statement except declarative statement.