当前位置:首页 » JAVA技术教程

【JAVA之反射方法的应用】

2018-11-02 08:21 本站整理 浏览(4)

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 + "]";
	}
	
}