- 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);
- Related Articles
- Method of Object class in Java
- Object class in Java
- Types of access modifiers in Java?
- Access Modifiers in Java
- Object and class in Java
- Object class in java programming
- What is the object class in Java?
- What are access modifiers and non-access modifiers in Java?
- What are the differences between access modifiers and non-access modifiers in Java?
- Java Object Creation of Inherited Class
- Create a Date object using the Calendar class in Java
- Get super class of an object in Java
- How to access the object of a class without using the class name from a static context in java?
- What are Java modifiers?
- Non Access Modifiers in Java\n

Advertisements