具体步骤如下:
首页,在testApp.java 类中定义属性,例如:public Sting name;
其次,Alt+Shift+S, 选择Generate Getters and Setter...这一项,然后如图
就能得到
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(); } }
原文地址:https://www.cnblogs.com/lvxisha/p/11584597.html
时间: 2024-10-30 06:36:51