public class Student {
private String name;
private int age;
private String sex;
private String grade;
public Student(String name1,int age1,String sex1,String grade1){
this.name= name1;
this.age=age1;
this.sex=sex1;
this.grade=grade1;
}
public String study(String name){
String chengji =name + "chengjiyouxiu";
return chengji;
}
public static void main( String[] args ) {
Student stu = new Student("张三",19,"男","高二");
System.out.println(stu.name);
stu.study(stu.name);
String aa = stu.study(stu.name);
System.out.println(aa);
}
}
定义了属性,添加一个全属性的构造方法和一个study的方法返回。
特别注意带参数的构造方法。
java学习-简单的代码-全属性的构造方法和study方法返回
原文:https://www.cnblogs.com/wuxiaobeistudy007/p/14860846.html