1/38
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
If an array component is of a primitive type, the component can be passed as a parameter to a method. (TRUE OR FALSE)
TRUE
int[] hit = new hit[5];
hit[0] = 3;
hit[1] = 5;
hit[2] = 2;
hit[3] = 6;
hit[4] = 1;
System.out.println(hit[1 + 3]);
What is the output of the code fragment above?
1
A method can have both a variable length formal parameter and other formal parameters. (TRUE OR FALSE)
TRUE
In a method call statement, when passing an array as an actual parameter, you use only its name. (TRUE OR FALSE)
TRUE
int[] num = new int[100];
for (int i = 0; i < 50; i++)
num[i] = i;
num[5] = 10;
num[25] = 100;
What is the index number of the last component in the array above?
99
int[] alpha = new int[5];
int j;
alpha[0] = 5;
for (j = 1; j < 5; j++)
{
if (j % 2 == 0)
alpha[j] = alpha[j – 1] + 2;
else
alpha[j] = alpha[j – 1] + 3;
}
What is the value of alpha[3] after the following code executes? (TYPE OUTPUT OR NONE)
13
Arrays can be initialized when they are created. (TRUE OR FALSE)
TRUE
int[] list = new int[25];
The statement creates list to be an array of 26 components because array index starts at 0. (TRUE OR FALSE)
FALSE
If a method has both a variable length formal parameter and other types of formal parameters, then the variable length formal parameter must be the last formal parameter of the formal parameter list. (TRUE OR FALSE)
TRUE
If an array index is less than zero, an InvalidIndexException exception is thrown. (TRUE OR FALSE)
FALSE
Suppose alpha is an array of 50 components. Which of the following about alpha is true?
(1) The base address of alpha is the address of alpha[0].
(2) The base address of alpha is the address of alpha[1].
(WRITE 1, 12, 2, OR NONE)
1
A method can have two variable length formal parameters. (TRUE OR FALSE)
FALSE
int[] x = new int[10];
x[0] = 34;
x[1] = 88;
System.out.println(x[0] + " " + x[1] + " " + x[10]);
What is the output of the code fragment above? (TYPE OUTPUT OR NONE)
NONE
Arrays have a fixed number of components. (TRUE OR FALSE)
TRUE
int[] list = new int[20];
list[12] = list[5] + list[7];
Given the declaration and the statement, it updates the content of the twelfth component of the array list. (TRUE OR FALSE
FALSE
The method toString creates a string that is the name of the object’s class, followed by the hash code of the object. (TRUE OR FALSE)
TRUE
According to the UML class diagram above, which of the following is a data member? (Clock(), min, printTime(), Clock)
min
Members of a class are usually classified into three categories: static, public, and void. (TRUE OR FALSE)
FALSE
Every object has access to a reference to itself. (TRUE OR FALSE)
TRUE
public class MyClass
{
private int x;
public void print()
{
System.out.println("x = " + x);
}
}
MyClass aa = new MyClass();
aa.print();
The aa.print(); statement is legal based on the code above. (TRUE OR FALSE)
TRUE
A mutator method of a class changes the values of the data members of the class. (TRUE OR FALSE)
TRUE
The modifier static in the heading specifies that the method can be invoked by using the name of the class. (TRUE OR FALSE)
TRUE
How many finalizers can a class have? (NUMBER ONLY)
1
public class Rectangle
{
private double length;
private double width;
public Rectangle()
{
length = 0;
width = 0;
}
public Rectangle(double l, double w)
{
length = l;
width = w;
}
public void set(double l, double w)
{
length = l;
width = w;
}
public void print()
{
System.out.println(length + " " + width);
}
public double area()
{
return length * width;
}
public double perimeter()
{
return 2 * length + 2 * width;
}
}
Suppose that you have the following declaration.
Rectangle bigRect = new Rectangle(10, 4);
Which of the following statements are valid in Java? (Assume that console is Scanner object initialized to the standard input device.)
(i)
bigRect.length = console.nextDouble();
bigRect.width = console.nextDouble();
(ii)
double l;
double w;
l = console.nextDouble();
w = console.nextDouble();
bigRect.set(l, w);
(TYPE 1, 12, 2, OR NONE)
2
Members of a class consist of packages, methods, and libraries. (TRUE OR FALSE)
FALSE
An accessor method of a class first accesses the values of the data members of the class and then changes the values of the data members. (TRUE OR FALSE)
FALSE
If a member of a class is a method, it can (directly) access any member of the class. (TRUE OR FALSE)
TRUE
Modifiers are used to alter the behavior of the class. (TRUE OR FALSE)
TRUE
A ____ is a collection of a fixed number of components. (TYPE IN CAPS)
CLASS
A constructor has the same name as the class. (TRUE OR FALSE)
TRUE
What is the arrangement of the array [11,2,13,21,25,19] after ONE iteration of outer loop to sort the data in INCREASING order using bubble sort algorithm (correct bubble sort).
Do not add spaces in the answer, follow this format [#,#,#,#,#,#].
[2,11,13,19,21,25]
What is the arrangement of the array [11,2,13,21,25,19] after ONE iteration of the outer loop to sort the data in INCREASING order using insertion sort algorithm.
Do not add spaces in the answer, follow this format [#,#,#,#,#,#].
[2,11,13,21,25,19]
What is the arrangement of the array [11,2,13,21,25,19] after TWO iterations of outer loop to sort the data in INCREASING order using bubble sort algorithm (correct bubble sort).
Do not add spaces in the answer, follow this format [#,#,#,#,#,#].
[2,11,13,19,21,25]
What is the arrangement of the array [10,52,63,1,85,9] after THREE iterations of the outer loop to sort the data in DECREASING order using selection sort algorithm.
Do not add spaces in the answer, follow this format [#,#,#,#,#,#].
[85,63,52,1,10,9]
What is the arrangement of the array [11,2,13,21,25,19] after FOUR iterations of the outer loop to sort the data in DECREASING order using insertion sort algorithm.
Do not add spaces in the answer, follow this format [#,#,#,#,#,#].
[25,21,13,11,2,19]
What is the arrangement of the array [11,2,13,21,25,19] after FOUR iterations of the outer loop to sort the data in DECREASING order using bubble sort algorithm (correct bubble sort).
Do not add spaces in the answer, follow this format [#,#,#,#,#,#].
[25,21,19,13,11,2]
What is the arrangement of the array [11,2,13,21,25,19] after ONE iteration of the outer loop to sort the data in INCREASING order using selection sort algorithm.
Do not add spaces in the answer, follow this format [#,#,#,#,#,#].
[2,11,13,21,25,19]
What is the arrangement of the array [10,52,63,1,85,9] after ONE iteration of the outer loop to sort the data in INCREASING order using selection sort algorithm.
Do not add spaces in the answer, follow this format [#,#,#,#,#,#].
[1,52,63,10,85,9]
What is the arrangement of the array [10,52,63,1,85,9] after TWO iterations of the outer loop to sort the data in INCREASING order using insertion sort algorithm.
Do not add spaces in the answer, follow this format [#,#,#,#,#,#].
[10,52,63,1,85,9]