Why do two programs have forward referencing errors while the third does not?

前端 未结 4 478
粉色の甜心
粉色の甜心 2020-12-09 07:15

The following does not compile, giving an \'illegal forward reference\' message:

class StaticInitialisation {

    static
    {
        System.out.println(\"         


        
4条回答
  •  不思量自难忘°
    2020-12-09 07:43

    Here what we have to understand is that in 2nd code snippet You are using block and this keyword.

    1. The block executes if object is created.
    2. That means the object is created in heap area.
    3. You are externally using this keyword to get a value of instance variable.
    4. Here object created with default values that will return as value.
    5. With out using this keyword you can't compile 2nd snippet also.

提交回复
热议问题