Hi Renuka,
U are absolutely correct. A class can have public / private / protected constructors
A class can be designed to prevent code outside the class declaration from creating instances of the class by declaring at
least one constructor, to prevent the creation of an implicit constructor, and declaring all constructors to be private.
See the follwing code
class Base{
private Base(){
System.out.println("Private Base Constructor");
}
}
public class Test extends Base {
Test(){
System.out.println("Child Constructor");
}
public static void main (
String args []) {
new Test();
}
}
This code gives compilation error
Test.java:8: No constructor matching base() found in class Base. Test(){
Because a class having a private constructor can't be instantiated (here Test is a form of base).
Hope this clears your doubt.
Aruna.