getDeclaredFields_Methods1
 

Complete Code:

import java.io.*;
import java.lang.reflect.*;
import java.net.InetAddress;
public class ClassTemplate1 {
/**
*
*/
public ClassTemplate1() {// TODO Auto-generated constructor stub
}
public static void main( String[] args )throws IOException
{
System.out.println("----");
try
{
Class<?> cls = Class.forName("Process");
Method md[] = cls.getDeclaredMethods();
for(int i=0; i< md.length; i++ )
{ System.out.println(md[i]); }
System.out.println("----");
//
Field fld[] = cls.getDeclaredFields();
for(int i=0;i< fld.length; i++)
{ System.out.println(fld[i]);
//System.out.println( fld[i].getName() + " modifiers " + fld[i].getModifiers());
}
}
catch(Exception e)
{ e.printStackTrace();}
}
}
//
class Process{
Process() {System.out.println("Constructor Invoked"); }
public void show(){}
void display(){}
public String str1 = " this is a string ";
public String str2 = " this is a string ";
public int n1 = 12; public int n2 = 24;
protected int n3 = 24;
}

 
Runtime view