How prevent inheritance in java without final?

Answer:

Answer

Make the constructor private.

Uhm, how would you make a instance of this class then?

Why don't you want inheritance? I don't understand!

Answer:

You can create the class without the public declaration. In such a case the access for that class would be default and hence you cannot extend that specific class outside its package. Still you can extend this class within its package.


The purpose of having the final keyword is to ensure that the class is not inherited. doing it without final is like touching your nose around your head when you can do it straightaway...

Note: There are comments associated with this question. See the discussion page to add to the conversation.
First answer by ID3580894453. Last edit by Anandvijayakumar. Contributor trust: 782 [recommend contributor recommended]. Question popularity: 11 [recommend question].