Variables having same name but different type

后端 未结 4 1378
无人及你
无人及你 2020-12-09 23:32

I have read here that in Java it is possible for two variables having same name but different type to co-exist in the same scope. What I mean is this

class te         


        
4条回答
  •  甜味超标
    2020-12-10 00:18

    According to the specification of the language (JLS 8.3):

    It is a compile-time error for the body of a class declaration to declare two fields with the same name.

    The statement that you've quoted is about a class file (i.e. a compiled file, not the source code).

提交回复
热议问题