Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: constructors

  1. #11
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Er... no.

    You don't return anything from a constructor. That's why it has no return type.

    There's no need to even have a constructor if you're not going to do anything with it.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  2. #12
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Im doing somethign that makes me need to write a constructor that includes the name of a person, their address and income. How would i do that?

  3. #13
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    What do you mean it needs to "include" the name, address, and income of a person? You mean those details should be passed to it?
    Code:
    class Person {
      String name, address;
      float income;
    
      Person(String name, String address, float income) {
        this.income = income;
        this.address = address;
        this.name = name;
      }
    }
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #14
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    include meaning contain it. ( im really not sure). i think its saying that i need to have it in it. I think what you have might be what i need but i dont understand the this.income, this.address etc part.

    Sorry to be so unclear about what i need. im not so sure myself.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •