/*创建对象类型数组*/
public class Leishuzu { String name; //属性 public static void main(String[] args){ Leishuzu dog1 = new Leishuzu(); //普通创建对象 dog1.name = "Puppy"; dog1.bark(); Leishuzu[] myDogs = new Leishuzu[3]; //创建Leishuzu的数组 myDogs[0] = new Leishuzu(); // myDogs[1] = new Leishuzu(); myDogs[2] = dog1; //指向对象 for(int i= 0;i<3;i++){ myDogs[i].name = "Puppy" + i; //字符串拼接 myDogs[i].bark(); } } public void bark(){ //方法 System.out.println(name + " is barking"); } }