public interface AmericaDroid {
public abstract void fitting();
}
public interface ChinaDroid {
public abstract void say();
}
public interface GermanyDroid {
public abstract void song();
}
public class Droid implements GermanyDroid,AmericaDroid,ChinaDroid{
private int year;
private String country;
private String name;
public Droid() {
}
public Droid(int year) {
this.year = year;
}
public Droid(int year,String name,String country) {
this.year = year;
this.name=name;
this.country=country;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Droid [year=" + year + ", country=" + country + ", name=" + name + "]";
}
@Override
public void say() {
}
@Override
public void fitting() {
}
@Override
public void song() {
}
}
public class DroidTest {
/**
* @desc
* @author Weiliang Hu
* @date 2013-9-10
* @param args
*/
public static void main(String[] args) {
Droid mDroid = new Droid();
System.out.println("mDroid class Name:" + mDroid.getClass().getName().toString());
System.out.println("获取类名称:");
Class> test1 = null;
Class> test2 = null;
Class> test3 = null;
try {
test1 = Class.forName("cn.iworker.reflex.Droid");
} catch (ClassNotFoundException e) {
System.out.println("not found Droid Class");
e.printStackTrace();
}
test2 = new Droid().getClass();
test3 = Droid.class;
System.out.println("test1 class Name:" + test1.getName().toString());
System.out.println("test2 class Name:" + test2.getName().toString());
System.out.println("test3 class Name:" + test3.getName().toString());
Droid mDroid1 = null;
try {
mDroid1 = (Droid) test1.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
mDroid1.setCountry("America");
mDroid1.setYear(1956);
mDroid1.setName("fnic");
System.out.println(mDroid1.toString());
Constructor> cons[] = mDroid1.getClass().getConstructors();
try {
mDroid1 = (Droid) cons[0].newInstance(2003, "snick", "Japan");
System.out.println("mDroid3 name" + mDroid1.toString());
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
for (int i = 0; i < cons.length; i++) {
System.out.println("Droid 的构造函数:" + cons[i]);
}
Class> inters[] = mDroid1.getClass().getInterfaces();
for (int i = 0; i < inters.length; i++) {
System.out.println("Droid 实现的接口----->>" + inters[i]);
}
}
}
mDroid class Name:cn.iworker.reflex.Droid
获取类名称:
test1 class Name:cn.iworker.reflex.Droid
test2 class Name:cn.iworker.reflex.Droid
test3 class Name:cn.iworker.reflex.Droid
Droid [year=1956, country=America, name=fnic]
mDroid3 nameDroid [year=2003, country=Japan, name=snick]
Droid 的构造函数:public cn.iworker.reflex.Droid(int,java.lang.String,java.lang.String)
Droid 的构造函数:public cn.iworker.reflex.Droid(int)
Droid 的构造函数:public cn.iworker.reflex.Droid()
Droid 实现的接口----->>interface cn.iworker.reflex.GermanyDroid
Droid 实现的接口----->>interface cn.iworker.reflex.AmericaDroid
Droid 实现的接口----->>interface cn.iworker.reflex.ChinaDroid