skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Monday, October 1, 2012

Program to print Modifiers of given class

Posted by Admin at 6:09 AM – 0 comments
 


import java.lang.reflect.*;
public class Refl5 {
	public static void printModifiers(String name)
	{
		try
		{
			Class c =Class.forName(name);
			int x=c.getModifiers();
			System.out.println("x value is"+x);

			if(Modifier.isPublic(x))
				System.out.println("\t public");
			if(Modifier.isFinal(x))
				System.out.println("\t final");
			if(Modifier.isAbstract(x))
				System.out.println("\t Abstract");


		}
		catch(ClassNotFoundException cnf)
		{
			cnf.printStackTrace();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	public static void main(String args[])
	{
		printModifiers(args[0]);
	}
}


Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger