题解 | #类型判断#
类型判断
https://www.nowcoder.com/practice/97223208ca954e67832da716b46e5d72
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(); Base obj = (Base) Class.forName(className).newInstance(); System.out.println(getClassName(obj)); } } public static String getClassName(Base obj) { //write your code here...... return obj.toString(); } } class Base { public String toString() { return "Base"; } } class Sub1 extends Base { public String toString() { return "Sub1"; } } class Sub2 extends Base { public String toString() { return "Sub2"; } }
java相关 文章被收录于专栏
java刷题,或许会有其他方面