Forward Referencing in Java

Haider Ali
Java by coding examples
Jan 19, 2024
class P006_ForwardReference
{
public static void main(String args[])
{
A a=new A();
System.out.println(a.x); // 100
}
}

class A
{
//int m=n; illegal forward reference
int n=30;
int x=getVal();

int getVal() { return 100; }
}

--

--