Type the three ways to obtain a Class object
Type the three ways to obtain a Class object
Answer
Class<?> a = obj.getClass(); Class<String> b = String.class; Class<?> c = Class.forName("java.lang.String");
getClass() returns the runtime type of a live object; the .class literal is compile-time and exception-free; Class.forName resolves a name String at runtime and throws ClassNotFoundException.