Take a look at the effects of the three programs of the following, it is a bit:
1) Correct program public class mytest {public static void main (String [] args) throws exception {mytest mytest = new mytest (); list list = new arraylist (); myobject t; for (int i = 0; i < 3; i ) {t = mytest.new myObject (); t.SetId (i); list.add (t);} t = null; for (int i = 0; i <3; i ) {system.out .println ((MyObject)). getId ());}}} class myObject {long ID; / ** * @return Returns ID. * / Public long getId () {return;} / ** * @PARAM ID To set the ID. * / Public void setid (long id) {id = id;}}
}
2) Error program PUBLIC CLASSITEST {public static void main (string [] args) throws exception {mytest mytest = new mytest (); list list = new arraylist (); myobject t = mytest.new myObject (); for (); for (); INT i = 0; i <3; i ) {T.SetId (i); list.add (t);} t = null; for (int i = 0; i <3; i ) {system.out.println ((MyObject)). GetId ());}} class myobject {long ID; / ** * @return returns the ID. * / Public long getId () {return;} / ** * @PARAM ID To set the ID. * / Public void setid (long id) {id = id;}}
}
3) Correct but not very good program public class mytest {public static void main (string [] args) throws exception {mytest mytest = new mytest (); list list = new arraylist (); for (int i = 0; i <3; i ) {MyObject T = mytest.new myObject (); T.SetId (i); list.add (t); t = null;} for (int i = 0; i <3; i ) {system .out.println ((myObject)). getId ());}}} class myobject {long ID; / ** * @return returns ID. * / Public long getId () {return;} / ** * @PARAM ID To set the ID. * / Public void setid (long id) {id = id;}}}