1/18
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Object
An object is something that contains both state & behavior. They are instances if classes, and are specific versions of a class.
Class
The class is a template for creating an object.
Instance
A instance is a specific version of a class (same thing as an object).
Client of a Class
Using the methods and functionality without necessarily understanding how it works.
Constructor
Correct Answer
A constructor allows us to create a new instance of a class, usually initializing instance variables.
public Flower(String theName, String theColor, String theGenus, String theSpecies){}

Which of the following is the correct /* implementation */ code for the constructor in the Card class?
The private instance variables suit and value need to be initialized to the appropriate parameter values, cardSuit and cardValue, respectively, in the constructor.

Instance Method
An instance method is a piece of code called on a specific instance of the class. It is called with a receiver object.
int area = rectangle1.getArea();
Is there a difference between a getter and a accessor method?
No, they refer to the same idea.
Getter Method
A getter method lets you get access to some instance variables of an object.
public String getSender()
{
return sender;
}
Setter Method
A setter method lets you set the values of instance variables of an object.
public void setNumerator(int theNumerator)
{
numerator = theNumerator;
}
Why use getter and setter methods?
Validation, hide internal representation, may need to add more logic to these methods, safety- can control better what a client can access.
Class Methods
A method of a class that is common to all instances of a class, and is not called on an object instance.
Class Variables
A variable or attribute of a class that is common to all instances of a class.
Static Variables/Static Methods
If a variable or method belongs to the class and not the instance, it is considered a class variable or class method.
int x = Math.abs(-5); , private static int totalStudents = 0;
Wrapper Class
Wrapper classes provide a way to wrap primitive values in an object, so that primitive can do activities reserved for objects. Integer, Double.
Integer x = new Integer(12);
Autoboxing
Converting a primitive value to an object of a corresponding wrapper class. The Java compiler will also apply auto boxing when a primitive value is passed as a parameter to a method that expects an object of the corresponding wrapper class. It helps us write cleaner code.
Integer myInt = 53;
Unboxing
Converting an object of a wrapper type to its corresponding primitive value. The Java compiler will also apply unboxing when a wrapper value is passed as a parameter to a method that expects a primitive value.
Integer myInt = 53;
int myInt2 = myInt; ← unboxing
Java automatically converts between objects and primitives in the process of autoboxing and unboxing.
What happens when a Double is unboxed?
A Double is unboxed when it is converted to a primitive value.
Java automatically converts between objects and primitives in the process of autoboxing and unboxing.
What happens when a int is autoboxed?
Correct Answer
A int is autoboxed when it is converted to a Integer