• Post Reply Bookmark Topic Watch Topic
  • New Topic

illegal constructors  RSS feed

 
Vishal Kurkure
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why constructor cannot be marked abstract or final? please explain in detail..
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Constructors are not inherited. Constructors are not overridden. So... those two keywords don't make sense for constructors.

Henry
 
Vishal Kurkure
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry,I got why abstract cannot be used but see final means we cannot inherit it and constructor cannot be inherited so we can use it right?
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your reasoning is like saying you can put a sign at the mouth of a cave that says "You cannot knock on door" because there is no door. Both are true in a sense but neither one makes any meaningful sense. Java will not you write that kind of nonsensical thing though, thankfully.
 
Vishal Kurkure
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please explain me why it is illegal...without some philosophical logic.."as I am not writting that kind of nonsensical thing....thankfully."
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Final applies to inheritance. A private method is not inherited. So final does not apply to it because it it makes no sense to say you cannot inherit the method if it cannot be inherited at all in the first place.

In the same way, a cave has no door. So it makes no sense to say you cannot knock on the door if there is no door at all in the first place.

Do you see the similarity?
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't take it personally when I say it "makes no sense". It's not a criticism directed at you personally. All that means is that there's no meaningful reason to mark a private method as final.
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason I said "thankfully" was not to be snarky. It is because programmers often find it difficult to write clear, unambiguous code. Ambiguous code can also be illogical. Illogical code leads to confusion and bugs. Thankfully, the designers of the Java language realized that it would be illogical to mark a private method as final and did not allow programmers to do that at all. This saves us all from having to deal with this kind of basic logic error in addition to everything else that programmers can already do to make their code illogical. It's just one way they helped us not shoot ourselves in the foot and for that I am grateful.
 
Vishal Kurkure
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:Final applies to inheritance. A private method is not inherited. So final does not apply to it because it it makes no sense to say you cannot inherit the method if it cannot be inherited at all in the first place.

In the same way, a cave has no door. So it makes no sense to say you cannot knock on the door if there is no door at all in the first place.

Do you see the similarity?


thank's now understood completely....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!