1/90
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
________ represents an entity in the real world that can be distinctly identified.
An Object
________ is a construct that defines objects of the same type.
A class
An object is an instance of a ________
class
The keyword ________ is required to declare a class.
class
________ is invoked to create an object.
A constructor
The default value for data field of a boolean type, numeric type, object type is ________, respectively
false, 0, null
public class Test{
int x;
public Test(String t){
System.out.println("Test");
}
public static void main(String[] args){
Test test = new Test();
System.out.println(test.x);
}
}
The program has a compile error because Test does not have a default constructor
Java assigns a default value to a date member of a class if the data is not initialized
True
The default constructor has no arguments
True
You can access a class variable using a syntax like objectName.classVariable or ClassName.classVariable
True
Which one of the following statements are correct
char[][] charArray = {{'a','b'}, {'c','d'}}
Assume double[][] x = new double[4][5], what are x.length and x[2].length?
4 and 5
What is the index variable for the element at the first row and first column in array a?
a[0][0]
___is the physical aspect of the computer that can be seen
hardware
How many Elements are array matrix (int[][] matrix = new int[5][5])?
25
Assume int[][][] x = new char [2][5][3], how many elements are there in the array?
30
What is the printout of the following program?
program public class Test{
public static void main(String[] args){
int[][] values = {{3, 4, 5, 2}, {33, 6, 1, 2}};
for (int row = 0; row < values.length; row++){
java.util.Arrays.sort(Values[row].length; column++);
System.out.print(values[row][column]+" ");
System.out.println();
}
}
}
The program prints two rows 1 3 4 5 followed by 1 2 6 33
What is the output for the following code?
public class test{
public static void main(String[] args){
int[][] matrix =
{{1, 2, 3, 4},
{4, 5, 6, 7,},
{8, 9, 10, 11}'
{12, 13, 14, 15}};
for (int i=0; i < 4; i++)
System.out.print(matrix[i][1] + " ");
}
}
2 5 9 13
analyze the following code:
int[][] matrix = new int[5][5];
for (int column = 0; column < matrix[4].length; column++)
matrix[4][column] = 10;
After the loop the last row of the matrix is 10, 10, 10, 10, 10
Assume boolean[][] x = new boolean[5][7], what are x.length and x[2].length?
5 and 7
One byte has___bits
8
java was originally developed by a team led by James Gosling at Sun Microsystems
true
a java program block starts with an open brace ({) and ends with a closing brace (})
true
___is the java assignment operator
=
which of the following expression results in a value 1
37 % 6
-24 % 5 is
-4
the expression 4 + 20 / (3-1) * 2 is evaluates to
24
what is the value of (double)(5/2)
2.0
to assign a double variable d to an int variable x, you write
x=(int)d;
the equal comparison operator in java is
==
which of the following code displays the area of a circle if the radius is positive
if (radius > 0) system.out.println(radius radius 3.14159);
analyze the following code
boolean even = false;
if (even = true) {
system.out.println("It is even!");
the program runs fine and displays It is even!.
what is y after the following switch statement
int x= 0;
int y = 0;
switch (x + 1) {
case 0: y=0;
case 1: y=1;
default: y = -1
}
-1
The following code displays ___________.
double temperature = 50;
if (temperature >= 100)
System.out.println("too hot");
else if (temperature <= 40)
System.out.println("too cold");
else
System.out.println("just right");
just right
in a switch statement, the default case must appear last among all cases. Otherwise, it would result in a compilation error
false
in java, the word true is
a boolean literal
suppose isPrime is a boolean variable, which of the flollowing is the correct and beat statement for testing if isPrime is true
if (isPrime)
suppose x=1, y=-1, and z=1. What is the printout of the following statement
if(x>0)
if (y>0)
system.out.println("x>0 and y>0");
else if (z>0)
system.out.println("x<0 and z>0");
x<0 and z>0;
the "less than or equal to" comparison operator in Java is
<=
what is y after the following statement is executed?
x = 0;
y = (x > 0) ? 10 : -10;
-10
the value of a variable can be changed
true
a java application must have a main method
true
___translates high-level language program into machine language program
a compiler
When you create an array using the following statement, the element values are automatically initialized to zero
int[][] matrix = new int[5][5];
true
Assume x=4 and y=5, which of the following is true
x<5|| y<5
the order of the precedence (from high to low) of the operators binary +, *, &&, ||, & is:
*, +, &, ||, &&
which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?
((x<100) && (x>1)) || (x<0)
the not equal comparison operator in java is
!=
the ___ operator can be used to compare two values
relational
what is x after evaluating
x=(2>3) ? 2 : 3;
3
What is Math.round(3.6)?
4
What is Math.rint(3.6)?
4.0
To obtain the sine of 35 degrees, use _____.
Math.sin(Math.toRadians(35))
A java character is stored in ______.
Two bytes
Suppose x is a char variable with a value 'b'. What is the printout of the statement System.out.println(++x)?
c
Which of the following statement prints smith\exam1\test.txt?
System.out.println("smith\\exam1\\test.txt");
The Unicode of 'a' is 97. What is the Unicode for 'c'?
99
To check whether a char variable ch is an uppercase letter, you write ______.
(ch >= 'A' && ch <= 'Z')
What is the return value of "SELECT".substring(0, 5)?
"SELEC"
Math.pow(3, 3) returns ______.
27.0
How many times will the following code print "Welcome to Java"?
int count = 0;
while (count < 10) {
System.out.println("Welcome to Java");
count++;
}
10
Analyze the following statement:
double sum = 0;
for (double d = 0; d < 10;) {
d += 0.1;
sum += sum + d;
}
The program compiles and runs fine.
The following loop displays __________.
for (int i = 1; i <= 10; i++) {
System.out.print(i + " ");
i++;
}
1 3 5 7 9
Analyze the following fragment:
duble sum = 0;
double d = 0;
while (d !=10.0) {
d += 0.1;
sum += sum + d;
The program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers.
You can always convert a for loop to a while loop.
True
You can always write a program without using break or continue in a loop.
True
Which of the loop statements always have their body executed at least once.
The do-while loop
What is the output of the following fragment?
int i = 1;
int j = 1;
while (i < 5) {
i++;
j = j * 2;
}
System.out.println(j);
16
A variable declared in the for loop control can be used after the loop exists.
False
Which of the following expression yields an integer between 0 and 100, inclusive?
(int)(Math.random() * 101)
Suppose your method does not return any value, which of the following keywords can be used as a return type?
Void
The signature of a method consists of ______.
method name and parameter list.
Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as ______, which stores elements in last-in first-out fashion.
A stack
When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as ______.
Pass by value
You can define two methods in the same class with the same name and parameter list.
False
You must have a return statement in a non-void method.
True
You should fill in the blank in the following code with _______.
public class Test {
public static void main(String[] args) {
System.out.print("The grade is ");
printGrade(78.5);
System.out.print("The grade is ");
printGrade(59.5);
}
public static ______ printGrade(double score) {
if (score >= 90.0) {
System.out.println('A');
}
else if (score >= 80.0) {
System.out.println('B');
}
else if (score >= 70.0) {
System.out.println('C');
}
else if (score >= 60.0) {
System.out.println('D');
}
else {
System.out.println('F');
}
}
}
Void
Analyze the following code:
class Test {
public static void main(String[] args) {
System.out.println(xmethod(5));
}
public static int xmethod(int n, long t) {
System.out.println("int");
return n;
}
public static long xmethod(long n) {
System.out.println("long");
return n;
}
}
The program displays long followed by 5.
______ is a simple but incomplete version of a method.
A stub
Variables defined in the method header are called ______.
Parameters
The arraycopy method does not allocate memory space for the target array. The target array must already be created with memory space allocated.
True
What is the representation of the third element in an array called a?
a[2]
If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is ______.
3
What is the correct term for numbers[99]?
indexed variable
Assume int[] t = {1, 2, 3, 4}. What is t.length?
4
The array size is specified when the array is declared.
True
The array index is not limited to int type.
False
(for each loop) Analyze the following code:
public class Test {
public static void main(String[ ] args) {
double[ ] x = {2.5, 3, 4};
for (double value: x)
System.out.print(value + " ");
}
}
The program displays 2.5 3.0 4.0
In the following code, what is the printout for list1?
public class Test {
public static void main(String[ ] args) {
Int[] list1 = {1, 2, 3};
Int[] list2 = {1, 2, 3};
List2 = list1;
list1[0] = 0; list1 [1] = 1; list2[2] = 2;
for (int i = 0; i < list1.length; i+)
System.out.print(list1[i] + " ");
}
}
0 1 2
public class Test {
public static void main(String[ ] args) {
Int[] x = {1, 2, 3, 4};
Int[] y = x;
x = new int[2];
for (int i = 0; i < y.length; i++)
System.out.print(y[i] + " ");
}
}
The program displays 1 2 3 4
What is Math.rint(3.5)?
4.0