Association in java classes

Association :

Association is a general binary relationship that describes an activity between two classes. For example, a student taking a course is an association between the Student class and the Course class, and a faculty member teaching a course is an association between the Faculty class and the Course class. The following Student1 class and Class are designed to associate them with each other in such a way that Course class can handle the information of all students registered in a course by creating an array of Student class object.

associating java classes

associating java classes

Student Class

public class Student1 {

	private String name; //data fields
	private int id;
	Student1(){} // Constructor
// Methods
	public void setName(String name){ name;
	public String getName(){
	public int getId(){
	public void setId(int id){;

Course Class :

public class Course {

private  String courseName;
private  Student1[] students;
private int numberOfStudents;

public Course(String courseName) {
this.courseName= courseName;
this.numberOfStudents = 0;
this.students = new Student1[20];
public void addStudent(Student1 student) {
this.students[numberOfStudents] = student;
public Student1[] getStudents() {
return students;
public int getNumberOfStudents() {
return numberOfStudents;

public String getCourseName() {
return courseName;
public void dropStudent(Student1 student) {
int indx = findStudent(student);
for(int i=indx; i