나는 시험에 대한 실습으로 몇 가지 일을하고있다. 그러나 나는 내 머리를 돌릴 수없는 한 가지 점은 다른 반에서 한 반에 속한 변수를 사용하고 있다는 것이다.한 클래스의 변수를 Java의 다른 변수에서 사용하는 방법은 무엇입니까?
나는 Course 클래스와 Student 클래스가 있습니다. 클래스 코스는 모든 다른 코스를 저장하며, 단순히 수업에서 클래스 이름을 사용하는 것입니다. 여기
내 코스 클래스입니다 :public class Course extends Student
{
// instance variables - replace the example below with your own
private Award courseAward;
private String courseCode;
public String courseTitle;
private String courseLeader;
private int courseDuration;
private boolean courseSandwich;
/**
* Constructor for objects of class Course
*/
public Course(String code, String title, Award award, String leader, int duration, boolean sandwich)
{
courseCode = code;
courseTitle = title;
courseAward = award;
courseLeader = leader;
courseDuration = duration;
courseSandwich = sandwich;
}
}
그리고 여기 학생입니다 :
public class Student
{
// instance variables - replace the example below with your own
private int studentNumber;
private String studentName;
private int studentPhone;
private String studentCourse;
/**
* Constructor for objects of class Student
*/
public Student(int number, String name, int phone)
{
studentNumber = number;
studentName = name;
studentPhone = phone;
studentCourse = courseTitle;
}
}
내가 과정에서 '이를 확장'사용하여 수정 있습니까? 아니면 이것은 불필요한가요?
Student 용 생성자에서 Course 클래스의 'courseTitle'을 'studentCourse'변수에 할당하려고합니다. 그러나 나는 이것을 어떻게 수행 하는지를 간단히 생각할 수 없다!
미리 도움을 주셔서 감사합니다. 나는 당신의 의견을 기다리고 있습니다!
감사합니다.
이 경우에 대한 많은 매핑 조인 테이블 (등록 개체)이 필요하다고 생각하지 않습니다. (기존의 데이터베이스에서 유지해야 할 필요가 없다면) –
@ 존 : 그렇습니다. 그러나 OP는 분명히 OO를 오용하는 끔찍한 사례에 노출되어 있기 때문에이를 모델링하기위한보다 철저한 대안을 보여주고 싶습니다. –
이 좋습니다. –