Unit 2: Using Objects Flashcards

1
Q

A _____ is an instance of a class with defined ______

A

object, attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A _____ is the formal implementation, or blueprint, of the attributes and behaviors of an object

A

class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Used to initialize the attributes of an object

A

constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

information passed/declared for a constructor within its parentheses

ex. public Person (int height, String name, boolean home)

A

formal parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

keyword used to make a new object

A

new

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A ____ has no parameters and sets the instance variables for the object to default values

A

no-argument constructor

ex. Dog ted = new Dog();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The value an initialized variable has, or can be as a placeholder

A

null

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Define the behaviors for all objects of a class and consist of a set of instructions for executing the behavior

A

methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Methods that don’t have return values, so they just perform a action

A

void methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

constructors with the same name, but different parameters

A

overloading constructors
(CANNOT have two with the exact same parameters and name)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Methods that return a value that is the same type as the value given to manipulate (saved as variable, DOES NOT print calculation)

A

non-void methods

ex. average = calculation for average;
return average;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

String objects are _____.

A

immutable (no method can change the value of that particular String object)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

command to print a new line in java in a string

A

\n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

value returned by indexOf() method if string doesn’t contain letter/phrase

A

-1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

String method that returns a substring from the first index value to the last index value minus 1

A

String substring(int from, int to)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

String method that returns a substring from the index value to the end of the string

A

String substring(int from)

( returns substring(from, length) )

17
Q

method that tests if strings are the exact same letters in the exact same order

A

word1.equals(word2);

(note: put boolean in front to return true or false if they equal/don’t equal)

18
Q

String .compareTo Values (tests which strings come before another by length)

> 0 :
= 0 :
< 0 :

A

> 0 : longer than other string
= 0 : equal to other string
< 0 : shorter than other string

(note: all in reference to 1st string)

19
Q

methods that belong to a class instead of objects of a class

A

static methods

20
Q

Math.random() returns ____.

A

A double that is between 0.0 inclusive and less than 1.0

21
Q

Basic format for making a new object:

A

className objectName = new className(parameters);

22
Q

The first index of a string is ___.

A

0

23
Q

line of code used to make a substring:
What index values does the substring take?

A

str.substring(x, y);
from x to the index value before y

24
Q

line of code to tell you length of substring:

A

str.length();

24
Q

function to get a random number:
what values does it make?
what do you have to do to make them whole values?

A
  • Math.random();
  • random number including 0 but less than 1.0
  • usually gets cast to (int)
24
Q

function to take absolute value:
function to take square root:
function to use exponent:

A
  • Math.abs(num);
  • Math.sqrt(num);
  • Math.pow(num, exponent);
25
Q

formula to know range of numbers for Math.random()

A

(max number - min number + 1)
add the first number in range, multiply math by the parentheses