O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required