how to preventing inheritance:by a class declared as final then that calss cannot be inheritedwhen preventing the inheritance:suppose iy ur class no need to reused then only u can declare final .
Final is Keyword which is used to prevent a class to Extend..when to stop the inheritance is up to u..when u need u'r class not to be subclassed further more then we can prevent inheritance
inheritance is prevented when u are sure that your class is a child/leaf and cannot be parent of any other class.U are sure that class is already saturated with functionality and won't be much help by extending it.
If we make Final class we cannot extend, also if we make all the constructor private then we cannot extend that class, is this also prevents inheritence?
Two ways: - (1) mark the class as final (2) make its constructor private -- in this case we will also not be able to instantiate a class from any other class