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?
i
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?
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.
, , , , , " " -, . , ( , ;)).
Java , .
java .
: http://c2.com/cgi/wiki?SyntaxVsSemantics
: http://wiki.answers.com/Q/What_are_the_Differences_between_syntax_and_semantic_error