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

    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
    Destiny Islands
    Rep Power


    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, 12:50 PM
  2. Static String Return Type
    By Java_Developer in forum New To Java
    Replies: 17
    Last Post: 10-03-2009, 07:07 PM
  3. Method return type problem
    By McChill in forum New To Java
    Replies: 7
    Last Post: 05-05-2009, 10:21 PM
  4. The return type
    By Marcus in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 07: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