public class Box {
private int height;
private int weight;
private int width;
/**
* @param height
* @param weight
* @param width
*/
public Box (int height, int weight, int width) {
super ();
this .height = height;
this .weight = weight;
this .width = width;
}
public int getHeight () {
return height;
}
public void setHeight (int height) {
this .height = height;
}
public int getWeight () {
return weight;
}
public void setWeight (int weight) {
this .weight = weight;
}
public int getWidth () {
return width;
}
public void setWidth (int width) {
this .width = width;
}
}
public class FanSheTest {
/**
* @author 591791
* @param args
*/
public static void main (String[] args) {
Box box = new Box(11 , 22 , 33 );
try {
Method method = Box.class.getDeclaredMethod("getHeight" );
Object h = method.invoke(box);
int height = (int )h;
System.out.println("get height value: " + height);
} catch (NoSuchMethodException | SecurityException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
输出
get height value: 11