Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
8.6.7 Default Constructor
If a class contains no constructor declarations, then a default constructor that takes no parameters is automatically provided:
- If the class being declared is the primordial class
Object, then the default constructor has an empty body. - Otherwise, the default constructor takes no parameters and simply invokes the superclass constructor with no arguments.
A compile-time error occurs if a default constructor is provided by the compiler but the superclass does not have a constructor that takes no arguments.
If the class is declared public, then the default constructor is implicitly given the access modifier public(ยง6.6); otherwise, the default constructor has the default access implied by no access modifier. Thus, the example:
public class Point {
int x, y;
}
is equivalent to the declaration:
public class Point {
int x, y;
public Point() { super(); }
}
where the default constructor is public because the class Point is public.