• Post Reply Bookmark Topic Watch Topic
  • New Topic

Constructord  RSS feed

 
Mohnish Khiani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can a constructor be declared final???
 
Devaka Cooray
Marshal
Posts: 5649
765
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried making it final ?
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have tried and have the result, please share it by replying to this thread.

gary
 
puneeth poduri
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
this just a guess i did try and it gave an error
it said invalid modifier

i think its because when we call a constructor(ie new Constructorname()). the jvm overrides and calls your constructor and then returns an instance of that particular class
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
puneeth poduri wrote:hi,
the jvm overrides and calls your constructor and then returns an instance of that particular class

JVM overrides which constructor? There is no talk about overriding with constructor, only you've overloaded constructors.
 
Mohnish Khiani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes..it gives an error...but whats the sense to make a constructor final?
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you make a constructor final? It can't be overridden so it's pointless. Also a constructor can't be synchronized, static, abstract, strictfp and native.
 
Mohnish Khiani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks everyone for your replys
 
K Abhijit
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter Oet wrote:Why would you make a constructor final? It can't be overridden so it's pointless.


playing DEVIL's advocacy :
I disagree a bit: There COULD BE a requirement when one version of Constructor I DON'T want to pass it on (BUT still want to keep it public) .. rest I do...

Consider this:


 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K Abhijit wrote: . . . playing DEVIL's advocacy :
I disagree a bit: There COULD BE a requirement when one version of Constructor I DON'T want to pass it on (BUT still want to keep it public) .. rest I do... . . .
That sounds like an attractive idea, but you still won't get it past the compiler.
 
K Abhijit
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!