Thread: More Java Homework Help

Results 1 to 3 of 3
  1. #1 More Java Homework Help 
    Registered Member #Butthole's Avatar
    Join Date
    Apr 2012
    Posts
    88
    Thanks given
    3
    Thanks received
    14
    Rep Power
    37
    Here is the assignment we were provided with : https://www.dropbox.com/s/r52127frki...gnment%207.pdf
    Here is turtle.class : [Java] Turtle - Pastebin.com

    I really have no clue how to inherit or create a constructor. Can someone help and explain how to do this for me?

    Thanks guys,
    Jon
    Regards -
    #Butthole
    Reply With Quote  
     

  2. #2  


    Major's Avatar
    Join Date
    Jan 2011
    Posts
    2,997
    Thanks given
    1,293
    Thanks received
    3,556
    Rep Power
    5000
    A constructor creates a new instance of a class, called an object. To declare one, you just need the class name (see below). When extending a class, you have to provide parameters for that class' constructor as well, e.g.:

    Code:
    public class Animal {
    
        /*
        * The number of legs the animal has.
        */
        private int legs;
      
        /*
        * Creates the animal.
        *
        * @param legs The number of legs the animal has.
        */
        public Animal(int legs) { // Declare a constructor for the animal class.
            this.legs = legs;
        }
    
    }
    
    public class Dog extends Animal {
    
        /*
        * The bark sound the dog makes.
        */
        private String bark;
    
        public Dog(String bark) { // Declare a constructor for the dog class.
            super(4); // Provide the information to the parent class.
            this.bark = bark;
        }
    
    }
    Hopefully from looking at the above you can see how to complete your assignment. Reply with any questions and I'll answer them (and by the way, it's two days overdue).
    Reply With Quote  
     

  3. #3  
    Banned
    Join Date
    Mar 2014
    Age
    25
    Posts
    147
    Thanks given
    75
    Thanks received
    21
    Rep Power
    0
    what subject are you taking exactly?
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Java Homework Help
    By #Butthole in forum Homework
    Replies: 6
    Last Post: 03-21-2014, 05:39 AM
  2. Simple Java Homework, HELP!!
    By #Butthole in forum Homework
    Replies: 2
    Last Post: 03-13-2014, 01:48 AM
  3. Java homework help.
    By FoReal in forum Homework
    Replies: 12
    Last Post: 01-05-2014, 06:54 AM
  4. More of my java homework!
    By OhBabyItsAlex in forum Homework
    Replies: 9
    Last Post: 11-20-2013, 12:03 PM
  5. Replies: 6
    Last Post: 01-16-2009, 10:26 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •