题解 | #定义打印方法#
定义打印方法
https://www.nowcoder.com/practice/50b50ae39d65415a9fd70601d711e5af
import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { String className = scanner.next(); // print就是需要你定义的方法 print(Class.forName(className).newInstance()); } } //write your code here...... public static void print(Object obj){ System.out.print(obj.getClass().getName()); } } class First { public String toString() { return "First"; } } class Second { public String toString() { return "Second"; } } class Third { public String toString() { return "Third"; } }