The Object
parameter of Field#getInt must be an instance of class A
.
A a = new A();
int y = testnum.getInt(a);
Since the name
and number
fields are not static, you cannot get them from the class; you must get them from a particular instance of the class.