下面是代码:
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;public class ClassTest { /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
if(args.length!=1)
{
return;
}
try
{
Class c=Class.forName(args[0]);
Constructor[] cons=c.getDeclaredConstructors();

for(int i=0;i<cons.length;i++)
{
System.out.println(cons[i]);

}
Method[] ms=c.getDeclaredMethods();
for(int i=0;i<ms.length;i++)
{
System.out.println(ms[i]);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}}class Point
{
int x,y;
static
{
System.out.println("Loading Point");
}
void output()
{
System.out.println("x="+x+",y="+y);
}
Point(int x, int y)
{
this.x=x;
this.y=y;
}
}为什么没有打印出output()方法?

解决方案 »

  1.   

    Class c = Class.forName("包名.Point");//这样因为
    if(args.length!=1) 

    return; 

    这里你的直接回去了~不执行下面的了~
      

  2.   

    我已经在命令提示符下传递了Point的参数,
    构造方法可以正常显示,但是output()方法就是显示不出来
      

  3.   

    你说的没打印出是什么意思?没有执行的意思吗?还是没打印出
    void test.Point.output()的意思?
    你每调用当然没执行了
      

  4.   

    我是说没有打印出"void test.Point.output()"这句话
      

  5.   


                Point p = new Point(1, 1);
                Class cc = p.getClass();
                Method ms = c.getDeclaredMethod("output");
                ms.invoke(p);//调用方法
      

  6.   

    这是eclipse中的显示结果
    Point(int,int)
    public Point Point.clone()
    public java.lang.Object Point.clone() throws java.lang.CloneNotSupportedException
    public java.lang.String Point.toString()
      

  7.   

    一楼说的对
    Point前面要加包名
    你命令提示符下传递了Point的参数改下
      

  8.   

    怎么改?
    我的包名是Classinfo
      

  9.   

    你在命令行上写入的时候写入
    Classinfo.Point