Type the three ways to get a Class<?> object
Type the three ways to get a Class<?> object
Answer
Class<?> c1 = obj.getClass(); Class<String> c2 = String.class; Class<?> c3 = Class.forName("com.acme.Foo");
getClass() requires a live instance. .class is a compile-time literal — preferred when the type is known. Class.forName() takes a string and throws checked ClassNotFoundException.