I am learning ArrayList. The following program is very well Working. But my question is that in Line20 below
why can't I access the variable i ?
like below
System.out.println(myObjectArray.i);
Since i is having Default access and which we suppose to be able to access in the Objects.
Thanks for the reply.
public class ObjectArray {
int i;
/** Creates a new instance of ObjectArray */
public ObjectArray(int i) {
this.i=i;
}
ObjectArray returnMyObject(){
return this;
}
public String toString(){
Integer myInteger = new Integer(this.i);
return myInteger.toString(i);
}
public static void main(String[] temp){
ArrayList objArrayList = new ArrayList();
for(int i=0;i<10;i++){
ObjectArray objObjectArray = new ObjectArray(1);
objArrayList.add(objObjectArray);
}
System.out.println(objArrayList.size());
Object myObjectArray;
for(int j=0;j<objArrayList.size();j++){
myObjectArray = objArrayList.get(j);
System.out.println(myObjectArray);
//System.out.println(myObjectArray); Here is
my Doubt
//Line 20:
}
}
}
why can't I access the variable i ?
like below
System.out.println(myObjectArray.i);
Since i is having Default access and which we suppose to be able to access in the Objects.
Thanks for the reply.
public class ObjectArray {
int i;
/** Creates a new instance of ObjectArray */
public ObjectArray(int i) {
this.i=i;
}
ObjectArray returnMyObject(){
return this;
}
public String toString(){
Integer myInteger = new Integer(this.i);
return myInteger.toString(i);
}
public static void main(String[] temp){
ArrayList objArrayList = new ArrayList();
for(int i=0;i<10;i++){
ObjectArray objObjectArray = new ObjectArray(1);
objArrayList.add(objObjectArray);
}
System.out.println(objArrayList.size());
Object myObjectArray;
for(int j=0;j<objArrayList.size();j++){
myObjectArray = objArrayList.get(j);
System.out.println(myObjectArray);
//System.out.println(myObjectArray); Here is
my Doubt
//Line 20:
}
}
}