Introduction to Classes Flashcards
In order to create an object, we need a
constructor method
How do you create an instance?
Call the constructor within the main()
Example: Car ferrari = new Car();
For Car ferrari = new Car();, what type of data type is Car
A reference data type
How to add data to an object
Introduce instance variables
How to asign an instance variable something
Add a constructor and pass a parameter through
Formal Parameter
Specifices the type and name of data that can be passed into the method
Argument
The values passed in through method calls
Example: Car ferrari = new Car(“red”);
red is the argument
How to access a field
Using the dot operator
Ex: ferrari.color
How to use objects as parameters
public Bakery (Cupcake cupcakeType, double priceOf)
If you modify an object in another method, it will
change that object outside the method
What is a copy constuctor?
Will copy a reference object:
public Cupcake(Cupcake copy) {
flavor = copy.flavor;
sprinkles = copy.sprinkles;
}