标签:style ar os sp java div bs ad as
public class A extends AB{
String name;
int age;
public A (String name,int age){
super(name, age);
}
}
public class B extends AB{
String name;
int age;
public B(String name, int age) {
super(name, age);
}
}
public class AB {
String name;
int age;
public AB(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "AB [name=" + name + ", age=" + age + "]";
}
}
import java.util.ArrayList;
import java.util.List;
public class TestArrayList {
public static void main(String[] args) {
List<AB> list = new ArrayList<AB>();
list.add(new AB("lz", 20));
list.add(new AB("LZ", 20));
System.out.println(list.toString());
}
}
pasting
[AB [name=lz, age=20], AB [name=LZ, age=20]]
java 不同list 添加元素
标签:style ar os sp java div bs ad as
原文地址:http://www.cnblogs.com/love-you-girl/p/4118719.html