Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Constructord

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can a constructor be declared final???
 
Sheriff
Posts: 6632
1255
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried making it final ?
 
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
 
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
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure 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?
 
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
 
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:


 
Marshal
Posts: 70266
282
  • 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
 
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic