【JAVA之反射方法的應用】
阿新 • • 發佈:2018-11-02
JAVA之反射的應用
import java.util.HashMap; import java.util.Map; public class Child extends Parent { public int add(int a,int b){ return a+b; } public HashMap add(Student stu){ Map ma = new HashMap(); ma.put("stu", stu); return (HashMap) ma; } public Child(){ super(); Object obj = "Child()"; System.out.println(obj); //super(); } @Override public String handler(Object obj) { obj = "Child:"+obj; System.out.println(obj); super.handler(obj); return null; // return super.handler(obj); } public static void main(String[] args) { Child child = new Child(); child.handler("test"); } } Student類: public class Student { private String name; private int age; public Student() { } public Student(String name, int age) { super(); 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 "Student [name=" + name + ", age=" + age + "]"; } }