Discovering Class Modifiers

Class c = someObject.getClass();
											int mods = c.getModifiers();
											if (Modifier.isPublic(mods))
											System.out.println("public");
											if (Modifier.isAbstract(mods))
											System.out.println("abstract");
											if (Modifier.isFinal(mods))
											System.out.println("final");

In a class definition, keywords called modifiers can precede the class keyword. The modifiers available are: public, abstract, and final. To discover which modifiers have been applied to a given class, you first get a Class object representing that class using the getClass() method. Next, you would call the getModifiers() method on the class object to return a bitmapped int value representing the modifiers. You can then use static methods of the java.lang.reflect.Modifier class ...

Get Java™ Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.