How to restrict the class from extension without using final keyword
Anonimo
Never heard that without using final keyword we can restrict the class from extension. interviewer answer - by making constructor private. below code shows how the interviewer is wrong and his method is not full proof. If there are 2 constructor one which is private to restrict extension and one which is public for other initialization purpose then it fails to restrict the extension. public class Parent { int a; private Parent() {} public Parent(int a) {} } public class Child extends Parent { int a; public Child(int a) { super(a); } }