5月16日 CMS 周三

package com.www;

public class Dog {
    public int did;
    public String dname;
    private String dhobby;
    public Dog() {
        super();
        // TODO Auto-generated constructor stub
    }
    public Dog(int did, String dname, String dhobby) {
        super();
        this.did = did;
        this.dname = dname;
        this.dhobby = dhobby;
    }
    @Override
    public String toString() {
        return "Dog [did=" + did + ", dname=" + dname + ", dhobby=" + dhobby
                + "]";
    }
    public int getDid() {
        return did;
    }
    public void setDid(int did) {
        this.did = did;
    }
    public String getDname() {
        return dname;
    }
    public void setDname(String dname) {
        this.dname = dname;
    }
    public String getDhobby() {
        return dhobby;
    }
    public void setDhobby(String dhobby) {
        this.dhobby = dhobby;
    }


}
package com.www;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Test {
    public static void main(String[] args) throws Exception {
        //三种方式
        Class c1 = Class.forName("com.www.Dog");
        Class c2 = Dog.class;
        Dog d = new Dog();
        Class c3 = d.getClass();

        System.out.println(c1.getPackage());
        System.out.println(c1.getName());
        System.out.println(c1.getSuperclass());
        System.out.println(c1.getInterfaces());

        Object obj = c1.newInstance();
        System.out.println(obj);

        Field[] fields = c1.getFields();
        Field[] declaredFields = c1.getDeclaredFields();

        Method[] methods = c1.getMethods();
        Method[] declaredMethods = c1.getDeclaredMethods();

        Constructor[] constructors = c1.getConstructors();
        Constructor[] declaredConstructors = c1.getDeclaredConstructors();
    }
}

The man who fears losing has already lost.
怕输的人已经输了。
——乔治·马丁《权力的游戏》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值