`public class person {
private String name;
private int age;
public person() {//alt+shift+s 在加c,创建父类空参构造函数
super();
}
public person(String name, int age) {//alt+shift+s 在加o,根据成员变量,创建父类有参构造函数
super();
this.name = name;
this.age = age;
}
public String getName() {//alt+shift+s 在加r,创建get和set方法
return this.name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return this.age;
}
public void setAge(int age) {
this.age = age;
}
作者:铭记不如铭心
来源:CSDN
原文:https://blog.csdn.net/qq_24644517/article/details/82886727
版权声明:本文为博主原创文章,转载请附上博文链接!`
方法一:
public class Person2 {
private int age;
private String name;
我创建了一个类,里面有两个私有属性age和name。现在构造两个构造函数,一个不带参数,一个带参数。右键—>source—>Generate Constructors from Superclass,创建一个空参的构造函数;右键—>source—>Generate Constructors using Fields,创建一个带参数的构造函数。
public class Person2 {
private int age;
private String name;
public Person2() {
super();
}
public Person2(int age, String name) {
super();
this.age = age;
this.name = name;
}
}
方法二:
直接上shift+alt+s,然后选择Generate Constructors from Superclass或者Generate Constructors using Fields,分别构造空参和带参数的构造函数
作者:芳草碧连天lc
来源:CSDN
原文:https://blog.csdn.net/leichaoaizhaojie/article/details/52675734
版权声明:本文为博主原创文章,转载请附上博文链接!