Send a link to your students to track their progress
58 Terms
1
New cards
In order to run a static method, you must run it for a particular object (the current object)
False
2
New cards
In order to run an instance method, you must run it for a particular object (the current object)
True
3
New cards
An instance variable can be declared as "static"
False
4
New cards
The same class can contain some members that are static and some members that are non-static.
True
5
New cards
Which kinds of variables are given default values if you do not initialize them? (Local/ instance/static? Which ones?)
instance and static
6
New cards
Default value for all primitive types?
0
7
New cards
Default value for boolean statements
False
8
New cards
Default value for char
ASCII code for 0
9
New cards
Default value for reference variables
null
10
New cards
When writing JUnit tests, is it better to write many small tests, or a few long ones?
Many small ones
11
New cards
If a JUnit test has several separate ASSERTIONS in it, will the test continue after one of the assertions fails?
No
12
New cards
If a JUnit test suite has several different JUnit tests in it (separate methods), will the rest of the tests run after one of them fails?
Yes
13
New cards
In what kind of methods does it make sense to use "this"?
Instance methods and constructors
14
New cards
What does "this" refer to?
The "current object"
15
New cards
If you do not write any constructors, what values will instance variables that are REFERENCES be assigned?
null
16
New cards
Under what circumstances will Java provide a default constructor for you automatically?
If I don't write a constructor
17
New cards
What do term do you use when you insert an element onto a stack?
push
18
New cards
What do term do you use when you remove an element from a stack?
pop
19
New cards
When you push an entry into the stack does it go on the top or bottom?
top
20
New cards
When you pop an entry from the stack, does it come off the top or bottom?
top
21
New cards
In java, when you pass a reference variable as an argument to a method, it is possible for the method to modify the object to which the variable refers.
Yes
22
New cards
What does API stand for?
Application Programming Interface
23
New cards
What type of members would you look for when identifying members that are a part of the API for the class?
"public" members
24
New cards
If a member is declared as public, can it be accessed from inside the SAME class?
Yes
25
New cards
If a member is declared as public, can it be accessed from ANOTHER class?
Yes
26
New cards
If a member is declared as private, can it be accessed from inside the same class?
Yes
27
New cards
If a member is declared as private, can it be accessed from another class?
No
28
New cards
What is a "setter"?
A method that initializes an instance variable
29
New cards
What is a "getter"?
A method that returns the value of an instance variable
30
New cards
If you change a class in such a way that the API changes, then other classes which depend on this one will have to be re-coded.
True
31
New cards
If you change a class WITHOUT modifying the API, then other classes which depend on this one will have to be re-coded.
False
32
New cards
What package is the Scanner class located in?
java.util
33
New cards
What is full name of the Scanner class?
java.util.Scanner
34
New cards
What is accomplished when you type "import java.awt.Color;" at the top of a file?
The IDE will know you're talking about the Color class in the package called java.awt
35
New cards
Which java package is automatically imported in its entirety into every Java program you write?
java.lang
36
New cards
What method of the String class can be used to pick out one particular character in the string?
charAt
37
New cards
What method of the String class can tell you how many characters are in the String?
.length()
38
New cards
What is accomplished when you type "import java.awt.*;" at the top of a file?
You import EVERYTHING that is in the package java.awt.
39
New cards
What method of the String class can be used to compare to Strings for alphabetical order?
.compareTo()
40
New cards
What method of the String class can select a portion of an existing String?
substring
41
New cards
Describe how a continue statement behaves in a while loop.
Goes to the top of the loop and checks the condition.
42
New cards
Describe how a continue statement works in a for-loop
increments variable
43
New cards
Are String objects mutable or immutable?
immutable
44
New cards
Are Integer objects mutable?
no
45
New cards
Aliasing can lead to problems if the object is MUTABLE
True
46
New cards
Aliasing can lead to problems if the object is immutable
False
47
New cards
When passing an array of primitives to/from a method, is it safe to make a reference copy?
No, make a shallow copy.
48
New cards
How many ints are created by the statement: int[] a = new int[5]
5 ints; by default, 0
49
New cards
How many Strings are created by the statement: String[] a = new String[5]
Zero; Just null boxes
50
New cards
If you write a switch statement like this: switch(x) {...} What types could the variable x be?
int, short, byte, char, String
51
New cards
If you write a class without specifying a particular package, which package will it become part of?
default package
52
New cards
Another name for "parent" class
Superclass
53
New cards
What is a child of a parent class called?
Subclass
54
New cards
Declare an instance variable (a String called "y") in a way in which it will be visible ONLY in the class containing it.
private String y;
55
New cards
Declare an instance variable (a String called "x") in a way in which it will be visible everywhere in the project.
public String x;
56
New cards
Declare an instance variable (a String called "z") in a way in which it will be visible ONLY in classes that are in the same package as the class you are writing.
String z;
57
New cards
Make a copy constructor that references this constructor:
public Tomato (int diameter) { this.diameter = diameter; }
public Tomato (Tomato other) { this(other.diameter); }
58
New cards
What word describes an object whose state is initialized by a constructor, but then can never change any time after that?