AP® Computer Science A glossary
Default constructor
Course: AP® Computer Science A Shows up in: Unit 3: Class Creation
The no-parameter constructor Java provides when a class has no constructor written; it sets instance variables to default values.
Appears in the course and exam description (CED): 3.4.A.43.4.A.5
Default values: int 0, double 0.0, boolean false, and any reference type null. Once you write any constructor, Java no longer provides the default constructor.
public class Counter
{
private int count;
private boolean done;
// no constructor: new Counter() still works
public static void main(String[] args)
{
Counter c = new Counter();
System.out.println(c.count + " " + c.done);
}
}
Output:
0 false Learn it properly, with a checkpoint 3.4 Constructors