1/13
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What type is an array in Java?
Arrays in Java are homogeneous: Can only hold items of a single type
For-each
• e will take the value of each
element in the array nums.
• Written this way, the loop will
automatically go through each
element in nums.
• Don’t need to keep track of index
or conditions, it’s done for us.
what does clone() do?
The clone() method in Java creates a copy of an array or object, duplicating its elements and structure. This allows for independent manipulation of the cloned object without affecting the original.
What does == do?
• When we use == with objects, we test object equality.
• “Are these two variables referring to the same object?”
• Declaring arrays with identical literals yields different objects
What do use to check content equality?
Use Arrays.equals()
What is a class?
A Class is a blueprint for creating objects
What are objects?
If the class is the blueprint, the actual car is the object.
Objects are instances of Classes:
• A string object is an instance of the String class
in the same way that 7 is an instance of int
• Classes may implement methods (behaviors)
that their objects can invoke.
• I.e. subString(), charAt(), etc. from String class
Access specifier: private
Access specifier:
• Private means this variable cannot be
accessed from outside the Counter class.
Let’s add some properties and behaviors to Counter
Access specifier: Public
Access specifier:
Public means this method can be
accessed from outside the Counter class
Mutator
Also known as the setter method. Modifies object data
Accessor
Also known as the getter method. Retrieves object data.
Set method
• Set methods ensure all possible operations upon the data fields of a given class fall within the intended domain of that class
Constructors
A constructor can be used to initialize
object values or perform some behavior
upon object creation.
Every class must have a constructor. We
haven’t created one yet, but Java
synthesizes a default, empty constructor
for you if you don’t provide your own. • When we use new to create an object, we invoke its constructor.
Can two methods have the same name
Two methods can have the same name IF
their parameter lists are different