黑马程序员技术交流社区

标题: 构造方法. [打印本页]

作者: L番茄X    时间: 2015-5-20 23:01
标题: 构造方法.
class Student{
     private String name;
     private int age name;
     public Student (String name int age){
         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);
  }
  class Demo
{
   public static void main(String[]args)
{
     Student stu = new Student("小芳",16);
           stu.setName("小狗");
           stu.setAge(3);
     System.out.println(stu.getName+"---"+stu.getAge);

  }
}
//请大神看到后给出详细的注释可好.







欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2