Results 1 to 2 of 2
  1. #1
    kaka is offline Member
    Join Date
    Sep 2010
    Posts
    5
    Rep Power
    0

    Default why constructor doesn't have any return type?

    Can any one give answer asap....

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    4

    Default

    Because the constructor simply returns the new object automatically.
    Java Code:
    Integer a = new Integer(1);
    The constructor could look something like this:
    Java Code:
    public Integer(int x) {
        this.value = x;
    }
    It doesn't need to return anything because it is understood that the new Integer(1) is a reference to the new object being created.

Similar Threads

  1. Generic return type is not inferred in for-each loop
    By ranma173 in forum Advanced Java
    Replies: 5
    Last Post: 10-08-2010, 11:50 AM
  2. Static String Return Type
    By Java_Developer in forum New To Java
    Replies: 17
    Last Post: 10-03-2009, 06:07 PM
  3. Method return type problem
    By McChill in forum New To Java
    Replies: 7
    Last Post: 05-05-2009, 09:21 PM
  4. The return type
    By Marcus in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 06:28 AM

Posting Permissions

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