September 2019
Intermediate to advanced
816 pages
18h 47m
English
In order to get the modifiers (public, protected, private, final, static, abstract, and interface) of a class, we can call the Class.getModifiers() method. This method returns an int value representing each modifier as a flag bit. For decoding the result, we rely on the Modifier class, as follows:
int modifiers = clazz.getModifiers();System.out.println("Is public? " + Modifier.isPublic(modifiers)); // trueSystem.out.println("Is final? " + Modifier.isFinal(modifiers)); // trueSystem.out.println("Is abstract? " + Modifier.isAbstract(modifiers)); // false