老师麻烦检查下
来源:3-4 自由编程
小老哥丶
2020-06-13 19:36:38
Goods
package com.imooc.answer; public class Goods { private int gId; private String gName; private float gPrice; private String gDesc; public Goods() { } public Goods(int gId, String gName, float gPrice, String gDesc) { super(); this.gId = gId; this.gName = gName; this.gPrice = gPrice; this.gDesc = gDesc; } public int getgId() { return gId; } public void setgId(int gId) { this.gId = gId; } public String getgName() { return gName; } public void setgName(String gName) { this.gName = gName; } public float getgPrice() { return gPrice; } public void setgPrice(float gPrice) { this.gPrice = gPrice; } public String getgDesc() { return gDesc; } public void setgDesc(String gDesc) { this.gDesc = gDesc; } @Override public String toString() { return "商品 [Id=" + gId + ", 名称=" + gName + ", 价格=" + gPrice + ",描述=" + gDesc + "]"; } public void display() { System.out.println("商品信息"); } }
测试类:
package com.imooc.answer; import java.lang.reflect.Constructor; import org.junit.Test; import com.imooc.reflect.Person; public class Date { @Test /** * 无参 * @throws Exception */ public void demo1() throws Exception { Class class1=Class.forName("com.imooc.answer.Goods"); Constructor constructor =class1.getConstructor(); Goods goos=(Goods)constructor.newInstance(); goos.display(); } @Test /** * 有参 */ public void demo2() throws Exception { Class class1=Class.forName("com.imooc.answer.Goods"); Constructor con=class1.getConstructor(int.class,String.class,float.class,String.class); Goods good=(Goods)con.newInstance(1,"马桶",8888.8f,"这个马桶会聊天并自动清洁"); System.out.println(good); } }
1、麻烦老师检查下代码
2、我的eclipse在右键run的时候不会自动识别可以执行的方法了,怎么调整回来
1回答
同学你好,同学的代码完成的不错哦,很棒,继续加油!!
2、建议同学重启后再试试
如果我的回答解决了你的问题,请采纳,祝学习愉快.