(6-7) Flashcards

(72 cards)

1
Q

Data hiding, which means critical data stored inside the object is protected from code outside the object, is accomplished in Java by:

A

using the private access specifier on the class fields

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

The scope of a public instance field is:

A

the instance methods and methods outside the class

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

Instance methods do not have the key word static in their headers

A

True

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

A method that stores a value in a class’s field or in some other way changes the value of a field is known as a mutator method

A

True

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

The java.lang package is automatically imported into all Java programs

A

True

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

A method that gets a value from the class’s field but does not change it is known as a mutator method

A

False

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

For the following code, which statement is NOT true?

public class Circle
{
private double radius;
private double x;
private double y;
}

A

Y is available to code that is written outside the Circle class

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

It is common practice in object-oriented programming to make all of a class’s:

A

fields private

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

For the following code which statement is NOT true?

public class Sphere
{
private double radius;
public double x;
private double y;
private double z;
}

A

Z is available to code that is written outside the circle class

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

Java allows you create objects of this class in the same way you would create primitive values

A

String

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

The public access specifier for a field indicates that the attribute may not be accessed by statements outside the class

A

False

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

A class in not an object, but description of an object

A

True

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

An object can store data

A

True

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

A class specifies _________ and ______ that a particular type of object has

A

fields; methods

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

Look at the following statement:

import.java.util.*;

This is an example of:

A

A wildcard import

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

A constructor:

A

has the same name as the class

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

Which of the following statements will create a reference, str, to the String, “Hello, World”?

A

String str = “Hello, World”;

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

Which of the following are classes from the Java API?

A

Scanner, Random, and PrintWriter

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

You should not define a class field that is dependent upon the values of other class fields:

A

in order to avoid having stale data

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

Methods that operate on an object’s fields are called:

A

instance methods

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

Which of the following will create a reference, str, to the string, “Hello, World?”

  1. String str = new String(“Hello World);
  2. String str = “Hello, world”;
A

Both 1 and 2

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

Class objects normally have __________ that perform useful operations on their data, but primitive values do not.

A

methods

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

One or more objects may be created from a(n)

A

class

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

What is stored by a reference variable?

A

A memory address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Instance methods do not have this key word in their headers:
Static
26
A constructor is a method that:
performs initialization or setup operation
27
An access specifier indicates how the class may be accessed
True
28
The following package is automatically imported into all Java programs
java.lang
29
In UML diagrams, this symbol indicates that a member is public
+
30
Given the following code what will be the final amount when it is displayed?
522.00
31
In your textbook the general layout of a UML diagram is a box that is divided into three sections. The top section has the ________; the middle section holds ___________; the bottom section holds __________
class name; attributes or fields; methods
32
What does the following UML diagram entry mean? + setHeight(h : double) : void
A public method with a parameter of data type double that does not return a value
33
Overloading means multiple methods in the same class:
have the same name, but different parameter lists
34
In a UML diagram to indicate the data type of a variable enter:
the variable name followed by a colon and the data type
35
The term "no-arg-constructor" is applied to any constructor that does not accept arguments
True
36
When an object is passed as an argument to a method, what is passed into the method's parameter variable?
the object's memory address
37
Look at the following statement: import java.util.Scanner; This is an example of:
an explicit import
38
The scope of a private instance field is:
the instance methods of the same class
39
Another term for an object of a class is:
instance
40
A constructor is a method that is automatically called when an object is created:
True
41
What will be the value of x[1] after the following code is executed? int[] x = {22, 33, 44}; arrayProcess(x); public static void arrayProcess(int[] a) { for (int k = 0; k < 3; k++) { a[k] = a[k] + 5; } }
38
42
What would be the results of the following code? final int SIZE = 25; int[] array1 = new int[SIZE]; // Code that will put values in array1 int value = 0; for (int a = 0; a <= array1.length; a++) { value += array1[a]; }
This will cause the program to show an error
43
What will be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5};
An array of 6 values ranging from 0 through 5 and referenced by the variable x will be created
44
Declaring an array reference variable does not create an array.
True
45
Which of the following statements are TRUE about the following code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE];
- Declares array1 to be a reference to an array of long values - Creates an instance of an array with 10 long values - will allow valid subscripts in the range of 0-9 Answer - all of the above
46
For the following code, what will be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};
A reference to the string "ghi"
47
Subscript/index numbering always starts at what value?
0
48
Which of the following for loops(to print the size of each string) is valid given the following declaration? String[] names = {"abc", "def", "ghi", "jkl"};
for (int i = 0; i < names.length(); i++ System.out.println(names[i].length);
49
Once an array is created, its size cannot be changed.
True
50
What would be the results of the following code? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77}; int a = 10; if( x[2] > x[5]) a = 5; else a = 8;
a = 5
51
In Java, you do not use the new operator when you use a(n):
Initialization list
52
When an individual element of an array is passed to a method:
The method does not have direct access to the original array.
53
What will be the value of x[8] after the following code has been executed? final int SUB = 12; int[] x = new int[SUB]; int y = 20; for(int i = 0; i < SUB; i++) { x[i] = y; y += 5; }
60
54
When an array of objects is created with new, but not initialized, the array values are set to null.
True (check question)
55
Each array in Java has a public field named ______ that contains the number of elements in an array
length
56
What would be the results of the following code? final int SIZE = 25; int[] array1 = new int[SIZE]; // Code that will put values in array1 int value = 0; for (int a = 0; a < array1.length; a++) { value += array1[a]; }
Value contains the sum of all the values in array1
57
If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?
0 through 14
58
To compare the contents of two arrays, you must compare the elements of the two arrays one by one
True
59
What is the value of scores[2][3] in the following array? int [] [] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} };
94
60
To return an array of long values from a method, use this as the return type for the method.
long[]
61
Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement:
str[0].toUpperCase();
62
A ragged array is:
a two-dimensional array where the rows are of different lengths
63
What does the following statement do? double[] array1 = new double[10];
- Declares array1 to be a reference to an array of double values - Creates an instance of an array of 10 double values - Will allow subscripts in the range of 0-9 Answer - all of the above
64
What would be the results after the following code is executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; x = y; y = x;
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
65
When an array is passed to a method:
- A reference to the array is passed - It is passed just as an object - The method has direct access to the original Answer - all of the above
66
In memory, an array of String objects:
consists of elements, each of which is a reference to a String object
67
What will be returned from the following method? public static float[] getValue(int x)
An array of float values
68
If numbers is a two-dimensional array, which of the following would give the length of row r?
numbers[r].length
69
By default, Java initializes array elements with what value?
0
70
What will be the value of x[1] after the following code is executed? int[] x = {22, 33, 44}; arrayProcess(x[1]); public static void arrayProcess(int a) { a = a + 5; }
33
71
What would be the results after the following code is executed? int[] x = {22, 55, 83, 19}; int[] y = {36, 78, 12, 24}; for (int a = 0; a < x.length; a++) { x[a] = y[a]; y[a] = x[a]; }
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
72
An array can hold multiple values of several different types of data simultaneously
False