I have an Image class and I initialize an array as below. Here Java allow me to have only Image objects inside the images array. Why I am not able to assign string or any other values to the images array? In case of String [] names = new String[3]
names array can hold string values. So, is there anything in the String class which will allow only string to assign to names array and we cannot assign any object to names array?
Image[] images = new Image[3];
public class Image {
/** Instance variables **/
private String imgLoc;
private String imgDesc;
private int dimensionX;
private int dimensionY;
private boolean defaultImg;
/** Getter method for image location **/
public String getImgLoc() {
return imgLoc;
}
/** Setter method for image location **/
public void setImgLoc(String imgLoc) {
this.imgLoc = imgLoc;
}
public String getImgDesc() {
return imgDesc;
}
public void setImgDesc(String imgDesc) {
this.imgDesc = imgDesc;
}
public int getDimensionX() {
return dimensionX;
}
public void setDimensionX(int dimensionX) {
this.dimensionX = dimensionX;
}
public int getDimensionY() {
return dimensionY;
}
public void setDimensionY(int dimensionY) {
this.dimensionY = dimensionY;
}
public boolean isDefaultImg() {
return defaultImg;
}
public void setDefaultImg(boolean defaultImg) {
this.defaultImg = defaultImg;
}
}