I am trying to understand how inhertitance and ArrayList work, so I have this following code It has a class which is the database where data will be saved
public class Database {
ArrayList<Student> students;
ArrayList<Course> courses;
public boolean doesIDExist(ArrayList<RegistrationSystem> array, int id){
boolean exist = false;
for (RegistrationSystem array1 : array) {
if (array1.getId() == id) {
exist = true;
break;
}
}
return exist;
}
public boolean addStudent(int id, String name, String surname){
if( doesIDExist(students, id)){
return false;
}
students.add(new Student(id, name, surname));
return true;
}
}
Both Student and Course are subclasses of Registration System
public class RegistrationSystem {
protected int id;
public int getId() {
return id;
}
}
But I get an error in this line:
if( doesIDExist(students, id))
incompatible types: ArrayList< Student > cannot be converted to ArrayList< RegistrationSystem >
I cannot quite understand why I get this error!