- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Listing the Modifiers of a Class Object in Java
The modifiers for a class or an interface are returned by the java.lang.Class.getModifiers() method. These modifiers are encoded as an integer and they consist of the JVM’s constants for public, private, protected, final, abstract, static and interface.
A program that demonstrates this is given as follows −
Example
import java.lang.reflect.Modifier; public class Main { public static void main(String[] argv) throws Exception { int modifiers = String.class.getModifiers(); String modifierString = Modifier.toString(modifiers); System.out.println("The Modifier is: " + modifierString); } }
Output
The Modifier is: public final
Now let us understand the above program.
The method getModifiers() is used to obtain the modifiers for the String class. Then this is printed by using the method toString(). A code snippet which demonstrates this is as follows −
int modifiers = String.class.getModifiers(); String modifierString = Modifier.toString(modifiers); System.out.println("The Modifier is: " + modifierString);
Advertisements