Hi everyone, I'm a fairly new Java student and I need some help regarding subclass.

This is what I'm trying to do:

Basically, I created a Superclass called Person, and from it I created a subclass called CollegeMember. Now, I need to divide the CollegeMember subclass to "Lecturer", "Student" and "Technicians". (Please note that I cut off the methods since I don't think they are needed in this case.)

Person (superclass):

public class Person
{
    public Person() //constructors
    {
        
    }
    public Person(String n, String s, int a, int id, double w)
    {
        setName(n);
        setSurname(s);
        setAge(a);
        setId(id);
        setWeight (w);
    }
    
    private String name; // instance variables
    private String surname;
    private int age;
    private int id;
    private double weight;
}

CollegeMember: (subclass extending Person)

public class CollegeMember extends Person
{
    public CollegeMember(String name, String surname, int age, int id, double weight, String collegeName)
    {
       super(name, surname, age, id, weight);
       setCollegeName(collegeName);        
    }
    
    private String collegeName;

    public String getCollegeName() 
    {
        return collegeName;
    }

    public void setCollegeName(String collegeName) 
    {
        this.collegeName = collegeName;
    }
    
    public String attendAtTme(double time)
    {
        String aat = getName()+ " " + getSurname() + " is attending at " + time ; 
        return aat;
    }
}

Lecturer: (subclass of CollegeMember - please note that I have probably attempted the following code a few ten times, and I can't seem to get this right. So I just pasted my first attempt. )

public class Lecturer extends CollegeMember
{
    public Lecturer()
    {
        
    }
    
    public Lecturer(String n, String sn, int a, int id, double w, String cn, String d)
   { 
     
    }
    
    private String degree;
}

The error is in the brackets marked in red. "constructor CollegeMember cannot be applied to given types."

So, anyone has some free time to spare and try to help me out?

Thanks in advance!

Regards,
Tsuchino

You didn't provide CollegeMember with a zero-argument constructor, which your Lecturer constructors are trying to call implicitly.

Dumb me..... Thanks a bunch Ezzaral.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.