import java.lang.reflect.*;
class Rect
{ double width,height,area;
  public double getArea()
  { area=height*width;
    return area;
   }
 }
public class Example4_35
{ public static void main(String args[])
  { Rect rect=new Rect();
    Class cs=rect.getClass();
    String className=cs.getName();
    Constructor[] con=cs.getDeclaredConstructors();
    Field[] field=cs.getDeclareFields();
    Method[] method=cs.getDeclareMethods();
    System.out.println("类的名字:"+className);
    System.out.println("类中有如下的成员变量:");
    for( int i=0;i<field.length;i++)
    { System.out.println(field[i].toString()); 
     }
    System.out.println("类中有如下的方法:");
    for(int i=0;i<method.length;i++)
    { System.out.println(method[i].toString());
     }
    System.out.println("类中有如下的构造方法:");
    for(int i=0;i<con.length;i++)
    { System.out.println(con[i].toString());
     }
   }
 }
和书对照了 没发现自己敲错了 实在找不到哪错了 
错误提示
Example4_35.java:15: 找不到符号
符号: 方法 getDeclareFields()
位置: 类 java.lang.Class
    Field[] field=cs.getDeclareFields();
                    ^
Example4_35.java:16: 找不到符号
符号: 方法 getDeclareMethods()
位置: 类 java.lang.Class
    Method[] method=cs.getDeclareMethods();
                      ^
2 错误E:\j2se\book\4>java Example4_35
Exception in thread "main" java.lang.NoClassDefFoundError: Example4_35

解决方案 »

  1.   

    getDeclaredMethods();
    getDeclaredFields(); 漏了个d 
      

  2.   

        Field[] field=cs.getDeclaredFields();
        Method[] method=cs.getDeclaredMethods();
      

  3.   

    你写错了, 建议你用GUI来写这些,能有提示的GUI,
    我刚刚找了好久,发现和了一个dMethod[] method=cs.getDeclareMethods();-->
    Method[] method=cs.getDeclaredMethods();Field[] field=cs.getDeclareFields(); --->
    Field[] field=cs.getDeclaredFields(); 
      

  4.   

    getDeclaredMethods();
    getDeclaredFields(); 
      

  5.   


    估计服务器做了缓存,没更新,要么就是.net太破了