具体步骤如下:
  首页,在testApp.java 类中定义属性,例如:public Sting name;
  其次,Alt+Shift+S,  选择Generate Getters and Setter...这一项,然后如图
  Java怎样对一个属性设置set或get方法的快捷键
  

  就能得到

public String getName() {
      return name;
}
public void setName(String name) {
      this.name = name;
}

 

下面是使用demo

  

public class testApp {
    public String name;
    public int age;
    public String address;
    public String getName() {
        System.out.println("我的名字:"+name);
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        System.out.println("我的年龄:"+age);
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getAddress() {
        System.out.println("我的地址:"+address);
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    
    @Test //测试
    public void adad() {
        System.out.println("\n==时间信息===========");
        testApp a = new testApp();
        this.setName("张三");//赋值
        this.setAge(10);
        this.setAddress("郑州·河南");
        
        this.getAddress();//获取值
        this.getName();
        this.getAge();
    }

    
}

 


  

相关文章:

  • 2022-12-23
  • 2021-07-19
  • 2021-08-10
  • 2021-10-26
  • 2022-01-17
  • 2021-08-14
  • 2021-07-28
猜你喜欢
  • 2022-12-23
  • 2022-02-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-14
  • 2021-09-26
相关资源
相似解决方案