Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Problem with inheritance

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with inheritance

    public abstract class Member
    {
        private String membername;
        private int membermembershipYear;
        private char membergender;
        private char membertype;
        private int memberid;
     
        public Member(String name,int membershipYear, char gender, char type, int id)
        {
            membername = name;
            membermembershipYear = membershipYear;
            membergender = gender;
            membertype = type;
            memberid = id;
        }
     
        public String getname()
        {
            return membername;
        }
     
        public int getmembershipYear()
        {
            return membermembershipYear;
        }
     
        public char getgender()
        {
     
            return membergender;
        }
     
        public int getid()
        {
            return memberid;
        }
     
        public void setname(String nameIn)
        {
            membername = nameIn;
        }
     
        public void setmembershipYear(int membershipYearIn)
        {
            membermembershipYear = membershipYearIn;
        }
     
        public void setgender(char genderIn)
        {
            membergender = genderIn;
        }
     
        public void setid(int idIn)
        {
            memberid = idIn;
        }
     
        public String printDetails()
        {
           String allDetails;
           allDetails = "Name:" + membername
                         +"Membership Year:" + membermembershipYear
                         +"Gender(M or F):" + membergender
                         +"Type(A ot J):" + membertype
                         +"ID:" + memberid;
            return allDetails;
        }
    }


    public class JuvenileMember extends Member
    {
        private int parentGuardianId;
        private int yearOfBirth;
        private String medicalNotes;
     
        public JuvenileMember(String id,String Name, int membershipYear,char gender,Member parentGuardian,int yearOfBirth, String medicalNotes)
        {
            super(id, membershipYear, gender);
            parentGuardianId = MemberparentGuardian;
            yearOfBirth = yearOfBirth;
            medicalNotes = medicalNotes;
        }
    }


    --- Update ---

    my problem is with my variables id , membership and gender in the sub class

    Error comes up " cannot find symbol - constructor Member (java.lang.String,int,char)
    Gratefull for any help
    Last edited by jps; August 16th, 2013 at 03:31 PM. Reason: code tags


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Problem with inheritance

    For future reference please wrap your code in the code tags to preserve formatting (see Announcements - What's Wrong With My Code? )

    The error stats that the compiler cannot find that constructor. Take a close look at the Member class constructor, and how the line that throws the error is calling it: you've only got one constructor for the Member class and it accepts 5 parameters (whereas the JuvenileMember class tries to use a 3 parameter constructor)

  3. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem with inheritance

    I am confused do could you explain ??does it have to be a 5 parameter constructor to work ?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Problem with inheritance

    Quote Originally Posted by barry1888 View Post
    does it have to be a 5 parameter constructor to work ?
    It has to be able to find the Constructor to be able to call it. A 5 parameter constructor is not the same as a 3 parameter constructor.

    Suggested reading: Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

Similar Threads

  1. Java Inheritance problem
    By Grot in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 24th, 2013, 07:34 PM
  2. problem with inheritance
    By freedom12 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 29th, 2013, 04:59 AM
  3. Replies: 1
    Last Post: November 2nd, 2012, 04:56 AM
  4. Problem with inheritance??
    By bczm8703 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 19th, 2011, 06:13 AM
  5. Problem with OOP - Inheritance
    By connex in forum Object Oriented Programming
    Replies: 1
    Last Post: December 14th, 2009, 11:11 PM