-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJvmTest.java
More file actions
53 lines (44 loc) · 981 Bytes
/
JvmTest.java
File metadata and controls
53 lines (44 loc) · 981 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
// 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 JvmTest
{
public static void main(String []args)
{
Student s1 = new Student();
Class c1 = s1.getClass();
System.out.println( c1.getName() );
Method []m = c1.getDeclaredMethods();
for(Method method :m)
{
System.out.println( method.getName() );
}
Field []f = c1.getDeclaredFields();
for(Field field: f)
{
System.out.println(field.getName());
}
}
}
class Student
{
private String name;
private int rollNo;
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;
}
}