-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJvmTest2.java
More file actions
54 lines (45 loc) · 1017 Bytes
/
JvmTest2.java
File metadata and controls
54 lines (45 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// A Java program to demonstrate working of a Class type object created by JVM to represent .class file in memory.
// Java code to demonstrate use of Class object created by JVM
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class JvmTest2
{
public static void main(String []args)
{
Student s1 = new Student();
Class c1 = s1.getClass();
System.out.println( c1.getName() );
Method []m = c1.getDeclaredMethods();
for(int i=0; i<m.length; i++)
{
System.out.println( m[i].getName() );
}
Field []f = c1.getDeclaredFields();
for(int i=0; i<f.length; i++)
{
System.out.println(f[i].getName());
}
}
}
class Student
{
private String name;
private int rollNo;
public int age;
public String getName()
{
return name;
}
public void setName(String sName)
{
this.name = sName;
}
public int getRollNo()
{
return rollNo;
}
public void setRollNo(int sRollNo)
{
this.rollNo = sRollNo;
}
}