Initialization of Instance Variables in Java -
how instance variable id gets initialized 0 when have provided our own default constructor , did not initialize id in it? output comes id:0 status:b how id 0?
`class demo{ private int id; private char status; public demo(){ status = 'b'; } public void display(){ system.out.println("id:="+id+" status:"+status); } public static void main(string args[]){ demo ob = new demo(); ob.display(); } }`
below default intializations
the following chart summarizes default values above data types.
data type | default value (for fields) -----------------------+----------------------------- byte | 0 short | 0 int | 0 long | 0l float | 0.0f double | 0.0d char | '\u0000' string (or object) | null boolean | false
Comments
Post a Comment