Object Creation and Storage (Instantiation) - AP Computer Science A
Card 1 of 30
What is the syntax to create a new object of class Car?
What is the syntax to create a new object of class Car?
Tap to reveal answer
Car myCar = new Car();. Standard object creation: declare variable, use new, call constructor.
Car myCar = new Car();. Standard object creation: declare variable, use new, call constructor.
← Didn't Know|Knew It →
What is stored in a variable that holds an object reference?
What is stored in a variable that holds an object reference?
Tap to reveal answer
Memory address of the object. References are pointers to objects in heap memory.
Memory address of the object. References are pointers to objects in heap memory.
← Didn't Know|Knew It →
What happens if you attempt to use an uninitialized object reference?
What happens if you attempt to use an uninitialized object reference?
Tap to reveal answer
NullPointerException. Thrown when accessing methods on null references.
NullPointerException. Thrown when accessing methods on null references.
← Didn't Know|Knew It →
How do you instantiate an object with a parameterized constructor?
How do you instantiate an object with a parameterized constructor?
Tap to reveal answer
new ClassName(parameters). Pass arguments to constructor for custom initialization.
new ClassName(parameters). Pass arguments to constructor for custom initialization.
← Didn't Know|Knew It →
What is the result of 'Car myCar = null;'?
What is the result of 'Car myCar = null;'?
Tap to reveal answer
myCar points to no object. Reference is explicitly set to point nowhere.
myCar points to no object. Reference is explicitly set to point nowhere.
← Didn't Know|Knew It →
What does 'null' signify for an object reference?
What does 'null' signify for an object reference?
Tap to reveal answer
No object is referenced. Special value indicating absence of object reference.
No object is referenced. Special value indicating absence of object reference.
← Didn't Know|Knew It →
Correct the error: 'Car myCar = Car();'
Correct the error: 'Car myCar = Car();'
Tap to reveal answer
Car myCar = new Car();. Missing 'new' keyword required for object creation.
Car myCar = new Car();. Missing 'new' keyword required for object creation.
← Didn't Know|Knew It →
What is the purpose of the 'new' keyword?
What is the purpose of the 'new' keyword?
Tap to reveal answer
To create new objects. Allocates memory and initializes objects dynamically.
To create new objects. Allocates memory and initializes objects dynamically.
← Didn't Know|Knew It →
Identify the return type of a constructor.
Identify the return type of a constructor.
Tap to reveal answer
Constructors have no return type. Constructors initialize but don't return values.
Constructors have no return type. Constructors initialize but don't return values.
← Didn't Know|Knew It →
Find the error: 'new Car myCar = new Car();'
Find the error: 'new Car myCar = new Car();'
Tap to reveal answer
Remove 'new' before 'Car'. 'new' should only appear before constructor call.
Remove 'new' before 'Car'. 'new' should only appear before constructor call.
← Didn't Know|Knew It →
What is the consequence of not using 'new' keyword?
What is the consequence of not using 'new' keyword?
Tap to reveal answer
No object is instantiated. Objects must be created with new keyword.
No object is instantiated. Objects must be created with new keyword.
← Didn't Know|Knew It →
State the relationship between class and object.
State the relationship between class and object.
Tap to reveal answer
Class is a blueprint; object is an instance. Class defines structure; objects are actual instances.
Class is a blueprint; object is an instance. Class defines structure; objects are actual instances.
← Didn't Know|Knew It →
What is initialized when an object is instantiated?
What is initialized when an object is instantiated?
Tap to reveal answer
Object's fields. Constructor sets initial state of instance variables.
Object's fields. Constructor sets initial state of instance variables.
← Didn't Know|Knew It →
What does 'myCar = new Car();' do?
What does 'myCar = new Car();' do?
Tap to reveal answer
Instantiates a Car object. Allocates memory and initializes new Car object.
Instantiates a Car object. Allocates memory and initializes new Car object.
← Didn't Know|Knew It →
How do you invoke a method on an object?
How do you invoke a method on an object?
Tap to reveal answer
objectName.methodName();. Dot notation connects object reference to its methods.
objectName.methodName();. Dot notation connects object reference to its methods.
← Didn't Know|Knew It →
What is the result of 'Car[] cars = new Car[10];'?
What is the result of 'Car[] cars = new Car[10];'?
Tap to reveal answer
Array of 10 Car references. Array holds references, objects created separately.
Array of 10 Car references. Array holds references, objects created separately.
← Didn't Know|Knew It →
What is the difference between class and object?
What is the difference between class and object?
Tap to reveal answer
Class defines; object is instance. Class is template; object is concrete implementation.
Class defines; object is instance. Class is template; object is concrete implementation.
← Didn't Know|Knew It →
Identify the type of 'Car myCar;' where Car is a class.
Identify the type of 'Car myCar;' where Car is a class.
Tap to reveal answer
Object reference declaration. Declares variable to hold reference to Car object.
Object reference declaration. Declares variable to hold reference to Car object.
← Didn't Know|Knew It →
Identify the error: 'Car myCar = new Car()'
Identify the error: 'Car myCar = new Car()'
Tap to reveal answer
Missing semicolon. Statement terminator required after constructor call.
Missing semicolon. Statement terminator required after constructor call.
← Didn't Know|Knew It →
Identify the keyword used in Java for object instantiation.
Identify the keyword used in Java for object instantiation.
Tap to reveal answer
new. Creates objects by allocating memory and calling constructor.
new. Creates objects by allocating memory and calling constructor.
← Didn't Know|Knew It →
What does 'new' keyword do in object creation?
What does 'new' keyword do in object creation?
Tap to reveal answer
Allocates memory for the object. Reserves space in heap for object's instance variables.
Allocates memory for the object. Reserves space in heap for object's instance variables.
← Didn't Know|Knew It →
How do you call a constructor when creating an object?
How do you call a constructor when creating an object?
Tap to reveal answer
Using new keyword with class name. Constructor follows class name after new keyword.
Using new keyword with class name. Constructor follows class name after new keyword.
← Didn't Know|Knew It →
What is the result of using 'new' keyword on a class?
What is the result of using 'new' keyword on a class?
Tap to reveal answer
A new instance of the class is created. Each use of new creates a separate object instance.
A new instance of the class is created. Each use of new creates a separate object instance.
← Didn't Know|Knew It →
In Java, what is a constructor used for?
In Java, what is a constructor used for?
Tap to reveal answer
Initializing a new object. Sets initial values for object's instance variables.
Initializing a new object. Sets initial values for object's instance variables.
← Didn't Know|Knew It →
What happens if no constructor is defined in a class?
What happens if no constructor is defined in a class?
Tap to reveal answer
A default constructor is provided by Java. Java automatically provides a parameterless constructor.
A default constructor is provided by Java. Java automatically provides a parameterless constructor.
← Didn't Know|Knew It →
Identify the part of 'Car myCar = new Car()' that is a constructor call.
Identify the part of 'Car myCar = new Car()' that is a constructor call.
Tap to reveal answer
new Car(). Constructor call invokes the Car() constructor method.
new Car(). Constructor call invokes the Car() constructor method.
← Didn't Know|Knew It →
Which operator is used to access an object's methods?
Which operator is used to access an object's methods?
Tap to reveal answer
Dot operator (.). Accesses methods and variables of an object instance.
Dot operator (.). Accesses methods and variables of an object instance.
← Didn't Know|Knew It →
Which method is called automatically when an object is created?
Which method is called automatically when an object is created?
Tap to reveal answer
Constructor. Runs immediately when new keyword creates the object.
Constructor. Runs immediately when new keyword creates the object.
← Didn't Know|Knew It →
How can you declare an object reference without instantiation?
How can you declare an object reference without instantiation?
Tap to reveal answer
Car myCar;. Creates reference variable without allocating object memory.
Car myCar;. Creates reference variable without allocating object memory.
← Didn't Know|Knew It →
What does 'myCar = new Car();' do?
What does 'myCar = new Car();' do?
Tap to reveal answer
Instantiates a Car object. Allocates memory and initializes new Car object.
Instantiates a Car object. Allocates memory and initializes new Car object.
← Didn't Know|Knew It →