java - Class out of scope? -


in question answer "compilation fails", because in go method h1 out of scope. h1 looks public me, can explain why out of scope? when can method access other variables?

public class happy {   int id;   happy(int i) { id = i; }   public static void main(string [] args) {     happy h1 = new happy(1);     happy h2 = h1.go(h1);     system.out.println(h2.id);   }   happy go(happy h) {     happy h3 = h;     h3.id = 2;     h1.id = 3;     return h1;   } } 

this line defines

happy h1 = new happy(1); 

this inside scope of main(string[] args)

which why can't access outside { } of main.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -