您的位置:首页 > 汽车 > 新车 > 网站设计公司网站制作费用_江门桂城网站建设_微信推广方案_企业网站运营推广

网站设计公司网站制作费用_江门桂城网站建设_微信推广方案_企业网站运营推广

2024/12/28 10:21:30 来源:https://blog.csdn.net/a624135_/article/details/142453774  浏览:    关键词:网站设计公司网站制作费用_江门桂城网站建设_微信推广方案_企业网站运营推广
网站设计公司网站制作费用_江门桂城网站建设_微信推广方案_企业网站运营推广
package com.qcby;public class Person {private String name;public Integer age;Character sex;protected Integer height;public Person() {}public Person(String name) {this.name = name;}public Person(String name, Integer age, Character sex, Integer height) {this.name = name;this.age = age;this.sex = sex;this.height = height;}public void run() {System.out.println("人跑的很快");}private void fly(String name) {System.out.println(name+"很会飞");}int gerAge() {return age;}void method(Integer age , Character sex) {System.out.println(age + "  " + sex);}
}

 

package com.qcby.user;//成员变量赋值,输出值,执行构造器,运行方法
public class User {private String name;public Integer age;Character sex;protected Integer height;public User() {}public User(String name) {this.name = name;}private User(String name, Integer age, Character sex, Integer height) {this.name = name;this.age = age;this.sex = sex;this.height = height;}public void run() {System.out.println("人跑的很快");}private void fly(String name) {System.out.println(name+"很会飞");}int getAge() {return age;}void method(Integer age , Character sex) {System.out.println(age + "  " + sex);}@Overridepublic String toString() {return "Person [name=" + name + ", age=" + age + ", sex=" + sex + ", height=" + height + "]";}
}
package com.qcby.user;import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;public class Main {public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchFieldException {Class pclass = 	Class.forName("com.qcby.user.User");Constructor userconstructor  = pclass.getDeclaredConstructor();User user = (User) userconstructor.newInstance(null);Field namefield =  pclass.getDeclaredField("name");namefield.setAccessible(true);namefield.set(user, "qiqi");Field agefield =  pclass.getDeclaredField("age");agefield.set(user, 1);Field sexfield =  pclass.getDeclaredField("sex");sexfield.set(user, '2');Field heightfield =  pclass.getDeclaredField("height");heightfield.set(user, 11);System.out.println(user.toString());Method runmethod  =  pclass.getDeclaredMethod("run", null);Method flymethod =  pclass.getDeclaredMethod("fly", String.class);flymethod.setAccessible(true);Method getAgemethod =  pclass.getDeclaredMethod("getAge", null);Method methodmethod =  pclass.getDeclaredMethod("method", Integer.class,Character.class);runmethod.invoke(user, null);flymethod.invoke(user, "qiqi");getAgemethod.invoke(user, null);methodmethod.invoke(user, 11,'a');}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com