java - Read value of outer class from inner class -


public class main {      public static string s;     string a="hello";     string b="world";     s=a+b;       class demo{         string m;         m=main.this.s;          system.out.println(m);     }  } 

output should : hello world

i here try understand main thing. main class android activity class extends listactivity , demo class extends asynctask. need read value static string s doinbackground method.

an inner class can directly access variables without using object or class name. hence can directly refer outer class's variable without metioning name.

instead of m=main.this.s; can directly access variable s m=s;

its basic rule of object oriented programming inner class has full access of methods , variables of outter class.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -