Results 1 to 15 of 15
  1. #1
    wayenng is offline Member
    Join Date
    Dec 2012
    Posts
    35
    Rep Power
    0

    Default why constructor cannot be "fina'"?

    "A constructor cannot be abstract, static, final, native, or synchronized."

    I understand on why it can't be all of the above, except "final".
    why can't we have a final constructor, i understand constructors are not inherited, hence no chance/case of overriding etc. But why is it not allowed at all ?

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    878
    Rep Power
    11

    Default Re: why constructor cannot be "fina'"?

    constructor can't be overriden or inherited.then what is the need of final for it?
    Ramya:cool:

  3. #3
    wayenng is offline Member
    Join Date
    Dec 2012
    Posts
    35
    Rep Power
    0

    Default Re: why constructor cannot be "fina'"?

    Quote Originally Posted by RamyaSivakanth View Post
    constructor can't be overriden or inherited.then what is the need of final for it?
    the meaning of "constructor can't be overriden or inherited" is equal to final? hence it should be allowed to do so.
    or is it implicit final for constructor?
    or where is the definition described?

    thx

  4. #4
    wayenng is offline Member
    Join Date
    Dec 2012
    Posts
    35
    Rep Power
    0

    Default Re: why constructor cannot be "fina'"?

    just like interface, the "abstract" method is implicit hence i don't need to write it but even though i do so, it would not prompt error.

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: why constructor cannot be "fina'"?

    What's not to understand. Final refers to the ability to override something or not. Constructors by definition cannot be overridden. So it is pointless to allow the keyword and when you attempt to use it on a constructor it is 100% certainly a mistake and as such it must be reported as an error.

    Your whole line of questioning boils down to "why doesn't Java allow me to make a guaranteed mistake"
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    wayenng is offline Member
    Join Date
    Dec 2012
    Posts
    35
    Rep Power
    0

    Default Re: why constructor cannot be "fina'"?

    Quote Originally Posted by gimbal2 View Post
    What's not to understand. Final refers to the ability to override something or not. Constructors by definition cannot be overridden. So it is pointless to allow the keyword and when you attempt to use it on a constructor it is 100% certainly a mistake and as such it must be reported as an error.

    Your whole line of questioning boils down to "why doesn't Java allow me to make a guaranteed mistake"


    is there any contradiction on "final" ability and "Constructors by definition cannot be overridden"?

  7. #7
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: why constructor cannot be "fina'"?

    Nope.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    wayenng is offline Member
    Join Date
    Dec 2012
    Posts
    35
    Rep Power
    0

    Default Re: why constructor cannot be "fina'"?

    Quote Originally Posted by gimbal2 View Post
    Nope.
    Thats what i asked, why constructor can not be final if they are no contradiction!

    Maybe you could say "no reason, just save it"

    I can not find any pointful answer from you instead.

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: why constructor cannot be "fina'"?

    From the JLS.

    8.8 Constructor declarations

    "Constructor declarations are not members. They are never inherited and therefore are not subject to hiding or overriding."

    So to allow them to be declared final would contradict that statement since only members and classes can be declared final.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: why constructor cannot be "fina'"?

    A constructor can be made 'private' so that you can't do a super( ... ) from a subclass; there's no need to have 'final' constructors ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: why constructor cannot be "fina'"?

    Quote Originally Posted by wayenng View Post
    Thats what i asked, why constructor can not be final if they are no contradiction!

    Maybe you could say "no reason, just save it"

    I can not find any pointful answer from you instead.
    Sorry that I can't read your mind, you might want to try explaining yourself better.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    wayenng is offline Member
    Join Date
    Dec 2012
    Posts
    35
    Rep Power
    0

    Default Re: why constructor cannot be "fina'"?

    Quote Originally Posted by gimbal2 View Post
    Sorry that I can't read your mind, you might want to try explaining yourself better.
    I am not wondering someone to read my mind but to answer my question and Jim as well as Jos did.
    You better learn from both Senior Member and Moderator otherwise you are just a guy anymore.

  13. #13
    wayenng is offline Member
    Join Date
    Dec 2012
    Posts
    35
    Rep Power
    0

    Default Re: why constructor cannot be "fina'"?

    Thanks Jim and Jos

  14. #14
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: why constructor cannot be "fina'"?

    Quote Originally Posted by wayenng View Post
    You better learn from both Senior Member and Moderator otherwise you are just a guy anymore.
    Wow. Just, wow. Anybody have some popcorn left? I'll bring the beers, Grolsch ofcourse... :)
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  15. #15
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: why constructor cannot be "fina'"?

    Its almost a song. Wayengg went to ask a question. Dum dum dum dum dum. But he spent almost no time trying to think about it. Dumb dumb dumb dumb dumb. Instead of trying to improve it he just insults the people. Dumb dumb dumb dumb dumb.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 0
    Last Post: 12-07-2012, 08:29 AM
  2. Replies: 3
    Last Post: 10-30-2012, 03:06 PM
  3. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  4. Replies: 1
    Last Post: 10-20-2008, 07:35 AM
  5. "Cannont find symbol Constructor" error
    By Welsh in forum New To Java
    Replies: 7
    Last Post: 01-25-2008, 12:12 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
  •