What is called a forward reference in Java?

前端 未结 4 1145
借酒劲吻你
借酒劲吻你 2020-12-15 06:44

I have been through this question on legality of forward references but not clear as to what is meant by forward references in Java language . Can someone ple

4条回答
  •  情书的邮戳
    2020-12-15 07:11

    In simple terms it means referencing (accessing a variable, calling a function) that is further down in the code file.

       static int x=getY();
       static int y=5;
       static int getY() { return y; }
    
    • x's value is set to the result of getY()
    • getY() is called before y's value is set to 5
    • x's value is therefore 0 (default integer)
    • y's value is 5

提交回复
热议问题