public class Test { private int age; //构造方法不能有void,方法名必须和类名相同,构造方法不能返回值,可以有一个单独的return public Test(int a) { age = a; //System.out.println(age); } public void speak() { System.out.println(age); } } public class examp01 { public static void main(String[] args) { // TODO Auto-generated method stub Test test = new Test(20); test.speak(); } }