What is the purpose of a copy constructor?
To instantiate a new object by initializing its fields (aka instance variables) to the values of another object (of the same type)
What is the purpose of the equals() method?
Compares the member variables of two objects for equality
What are the three different type of constructors?
Parameterized, copy, default constructors
How would you correctly declare an integer array named numbers with 50 elements?
int[ ] numbers = new int[50];
What is inherited by a subclass?
protected and public instance variables and methods
What is the purpose of a default constructor?
To instantiate a new object by initializing its fields (aka instance variables) to null or default values.
What is the purpose of the toString() method?
Converts the object into a String for display
What is the difference between an object and a class?
Objects are an instance of a class, classes are "Blueprints" of an object
What is an index?
An index refers to a certain position in the array
What does the keyword extends do?
extends is used to state that the class is inheriting from a parent class
What is the purpose of a parameterized constructor?
To instantiate a new object by initializing its fields (instance variables) with the arguments coming into the constructor
What does Setters/Getter methods do?
Setters: Setter methods changes the value of one of the fields.
Getters: Getter methods return the value of one of the fields.
What methods does each class typically contain?
Constructors,Getters and Setters,Equals() and toString().
What is an element?
An element refers to the value at a certain position in the array.
What does the keyword super do?
super is used to refer methods in the parent class
True or False: A class in Java can have more than one constructor?
True
True or False: Getter methods should have the return type of "void"
False
What is class composition in Object Oriented Programming?
When a class references one or more objects of other classes in member variables (aka fields)
What does the .length property do?
it returns how many indices are within the array.
True or False: A parent class can inherit fields and methods from the child class
False
Create a Parameterized for the following class:
public class Computer {
private double mCPU;
private int mRAM;
private String mModel;
}
Public Computer(double cpu, int ram, String model){
mCpu = cpu;
mRam = ram;
mModel = model
}
In the Quiz class, the displayStats method has the following signature: public static void displayStats(int numGrades). How would you use the displayStats method?
Quiz.displayStats(parameter);
What are 3 access modifiers? What does each of them do?
Public-Classes, methods and fields are accessible from every where in the program.
Private- The methods and fields are accessible only within the class in which they are declared.
Protected-The methods and fields are accessible within same package or in child classes
Which loop is used to iterate through all the contents of a two-dimensional array?
nested for loops
What class does every class inherit from?
The Object class