Home Java Reflect Class Modifier Example
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Class Modifier Example

Advertisement
In this section you will learn how to retrieve modifier's information of a class that we have taken in our program.

Class Modifier Example

     

In this section you will learn how to retrieve modifier's information of a class that we have taken in our program. Here is an example that provides the usage of the getModifiers() method in more detail.

Create an object of  class as you want and then call getModifiers() method through this object. We can also know is it "Public", "Abstract", "Final" with isPublic(), isAbstract(), isFinal() methods.

Here is the code of example:

 

 

 

 

ClassModifier.java

import java.lang.reflect.*;

public class ClassModifier {
  public static void main(String str[]){
  Class cls = java.util.List.class;
  int modifier = cls.getModifiers();
  if (Modifier.isPublic(modifier))
 System.out.println("public");
  if (Modifier.isAbstract(modifier))
 System.out.println("abstract");
  if (Modifier.isFinal(modifier))
 System.out.println("final")
 }
}

Output:

Download Source Code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 10, 2008

Related Tutorials

Ask Questions?    Discuss: Class Modifier Example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Anjaneya
September 26, 2012
Regarding the document

Its realy nice document
DMCA.com