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 3 of 3

Thread: Programming assignment using inheritance

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Programming assignment using inheritance

    I am writing a java program focusing on inheritance. The super class reads in a file and I tokenize the line and send each token into its own array. There are 7 arrays with 9 slots in each one (because there are 9 lines of information and 6 tokens per line). I have to make a sub class extending from the super class, and I am having problems with my super class constructor and how the sub class will be able to access the information in any of the slots of any of the arrays. I understand the basic concept of inheritance, but am having trouble comprehending how to put arrays as parameters in the constructor and how the subclass will access those values.

    //Super Class constructor
     
    public Employee(String employFirstNames[], String employLastNames[], String employNumbers[], String employHireDates[], String employShiftNumbers[], String employHourlyRates[])
          {		
    			for(i = 0; i < employees.length(); i++)
    			{
             	                empFirstNames[] = employFirstNames[];
     
    				empLastName[] = employLastNames[];
     
    				empNumbers[] = employNumbers[];
     
    			 	empHireDates[] = employHireDates[];
     
    				empShiftNumbers[] = employShiftNumbers[];
     
    				empHourlyRates[] = employHourlyRates[];
    			}
          }
     
    //sub class constructor
     
    public ProWorker()
    	{
    		super(empFirstNames[], empLastNames[], empNumbers[], empHireDates[], empShiftNumbers[], empHourlyRates[]);
    	}
    Last edited by helloworld922; May 3rd, 2011 at 08:06 PM.


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

    Default Re: Programming assignment using inheritance

    The subclass constructor does not have any parameters, so based upon the info you provided cannot invoke the super class constructor. You can adapt the child class constructor to accept parameters and pass those to the parent class, or provide setters for those values which can be used to set the values, or access them directly if the child class has access. The first suggestion is demonstrated below:
    public class Parent{
        private String[] values;
        public Parent(String[] values ){
            this.values = values;
        }
    }
     
    public class Child extends Parent{
        public Child(String[] values){
            super(values);
        }
    }

  3. The Following User Says Thank You to copeg For This Useful Post:

    javapenguin (May 3rd, 2011)

  4. #3
    Junior Member
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you.

Similar Threads

  1. Java Inheritance Help
    By danielparry in forum Java Theory & Questions
    Replies: 3
    Last Post: March 17th, 2011, 03:20 PM
  2. Inheritance and Overriding help!
    By Knserbrave in forum Object Oriented Programming
    Replies: 4
    Last Post: February 24th, 2011, 01:46 PM
  3. programming assignment help
    By sdgseed in forum Threads
    Replies: 1
    Last Post: October 20th, 2010, 02:43 PM
  4. inheritance help
    By justin3492 in forum Object Oriented Programming
    Replies: 3
    Last Post: September 30th, 2010, 07:45 PM
  5. inheritance
    By b109 in forum Java Theory & Questions
    Replies: 3
    Last Post: May 30th, 2010, 09:23 PM