类与类之间的关系还有方法执行的问题
public class GradeBook { private String courseName; public GradeBook(String name){ courseName =name; } public void setCourseName(String name){ courseName=name; } public String getCourseName(){ return courseName; } public void displayMessage(){ System.out.printf("welcome to the grade book for\n%s!\n",getCourseName()); } }
上边是同一个包里的 GradeBook 类
下边是同一个包里的 GradeBookTest 类
public class GradeBookTest { public static void main(String[] args) { GradeBook gradeBook1=new GradeBook("flying"); System.out.printf("gradeBook1 course namm is %s\n",gradeBook1.getCourseName()); } }
GradeBook 类里边 setCourseName 方法到底执行了没有? GradeBookTest类里边没有见到另外谁能告诉我一下该代码的执行机理?多谢啦