📄 testnewcar.java
字号:
import java.lang.reflect.Constructor;public class TestNewCar{ public static void main(String args[]) { try { Class car = Class.forName("NewCar"); // create the array of parameter types and find the constructor Class param[] = {int.class}; Constructor con = car.getDeclaredConstructor(param); // use a wrapper class to hold the int argument 4 Object values[] = {new Integer(4)}; // create an instance of the class NewCar carObj = (NewCar)con.newInstance(values); System.out.println("The car has " + carObj.getTireCount() + " tires"); } catch (Exception e){ System.out.println("Something went wrong while instantiating NewCar"); e.printStackTrace(System.err); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -