A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© Kelvinhu 中级黑马   /  2014-4-14 23:44  /  926 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 Kelvinhu 于 2014-4-14 23:45 编辑

Constructor[] cons = Student.class.getConstructors();     //想要返回Student类中所有的构造方法,这样做为什么返回不了。。求解。

贴上代码。。。


  1. package Testpackage;

  2. import java.lang.reflect.Constructor;
  3. import java.lang.reflect.Method;
  4. import java.util.Date;

  5. public class Test {

  6.         public static void main(String[] args) throws Exception {
  7.                 // TODO Auto-generated method stub
  8.                 Student a = new Student();
  9.                 Class cls = a.getClass();
  10.                 System.out.println(cls);
  11.                 Method gstudy = cls.getMethod("study", null);
  12.                 System.out.println(gstudy);
  13.                 Constructor[] cons = Student.class.getConstructors();     //想要返回Student类中所有的构造方法,这样做为什么返回不了。。求解。
  14.                 for (Constructor co : cons) {
  15.                         System.out.println(co);
  16.                 }
  17.         }

  18. }

  19. class Student {
  20.         private int grade;
  21.         private static int teststatic;

  22.         Student() {
  23.                 this.grade = 0;
  24.         }

  25.         Student(int i) {
  26.                 this.grade = i;
  27.         }

  28.         public void study() {
  29.                 System.out.print("like study");
  30.                 grade = 100;
  31.                 teststatic = 0;
  32.         }

  33.         public void sleep() {
  34.                 System.out.print("like sleep");
  35.         }

  36.         static void play() {
  37.                 System.out.print("like play");
  38.                 teststatic = 0;
  39.         }

  40. }
复制代码


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马