~/ learn/ comp-308/ cards/ Type Information: RTTI & Reflection
1 of 16

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.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/e7932c93-b1e8-4e8f-8704-ad687296b92b/flashcard utf-8 LF