AP® Computer Science A glossary
Constructor
Course: AP® Computer Science A Shows up in: Unit 1: Using Objects and MethodsUnit 3: Class Creation
Code in a class that is called to create an object. It has the same name as the class and sets the object's initial attribute values.
Appears in the course and exam description (CED): 1.13.A.11.13.C.11.13.C.23.4.A.1
Call a constructor with new, as in new Plant("Fern", 30). The constructor runs all its statements, then control returns right after the call. (Unit 3 covers writing constructors.)
Plant p = new Plant("Fern", 30);
System.out.println(p.getName());
Output:
Fern Learn it properly, with a checkpoint 1.13 Object Creation and Storage (Instantiation)