A syntax or semantics problem?

The method below cannot be executed in Java, because the variable imay remain uninitialized until it is used. Is this a syntax or semantics issue?

public int odd( boolean b ){
    int i;
    if( b ){ i = 3;}
    return i;
}

I would think that it would be semantics, but according to my instructor, this is a syntax error. Is this correct and why?

+5
source share
2 answers

This is an error detected by the Java compiler, but it is not a syntax error; it works perfectly according to Java grammar. It is detected at later stages of analysis, which makes it a semantic error.

, , , , , " " -, . , ( , ;)).

+8

All Articles