问: 
     在成员方法中,int代表有明确的返回值,void代表没有明确的返回值。 
     getAge() 的返回值类型为int,因为知道返回的是int类型的年龄值,但是setAge 为什么不能用int修饰,而只能用void修饰呢? 
     public void setAge(int age) {}  这个括号里不是也定义了参数类型为int型吗?也就是说返回的就是int型的年龄值,为什么不能用int修饰整个方法? 
 
- public class Student {
 
 -         private String name;
 
 -         private int age;
 
 -         public Student() {
 
 -                 super();
 
 -                 // TODO Auto-generated constructor stub
 
 -         }
 
 -         public Student(String name, int age) {
 
 -                 super();
 
 -                 this.name = name;
 
 -                 this.age = age;
 
 -         }
 
 -         public String getName() {
 
 -                 return name;
 
 -         }
 
 -         public void setName(String name) {
 
 -                 this.name = name;
 
 -         }
 
 -         public int getAge() {
 
 -                 return age;
 
 -         }
 
 -         public void setAge(int age) {
 
 -                 this.age = age;
 
 -         }
 
 -         
 
 -         public void show(){
 
 -                 System.out.println("姓名:"+name+",年龄:"+age);
 
 -                 
 
 -         }
 
 - }
 
  复制代码 |   
        
 
    
    
    
     
 
 |