- //新曙光培训@西安
- //www.xinshuguang.org
- import java.util.*;
- class FanSheGouZao{
- int i;
- char c;
- public FanSheGouZao(int k){i=k;System.out.println("i="+i);}
- //如果要用getConstructor,则构造方法前面必须加public
- public FanSheGouZao(char ZiFu){c=ZiFu;System.out.println("c is "+c);}
- }
- public class FanSheGouZaoTest{
- public static void main(String[] args) throws Exception{
- Class type=FanSheGouZao.class;
- type.getConstructor(char.class).newInstance('M');
- //这句话相当于
- //new FanSheGouZao(8);
- //new FanSheGouZao('M');
- }
- }