What would a catch { } clause do in Java? Select one: a. pass an exception to an
ID: 3820108 • Letter: W
Question
What would a catch { } clause do in Java? Select one:
a. pass an exception to an exception handler
b. handle an exception and recover the program
c. return an exception to the try { } statement
d. halt the program
Which of the following statements would open a le named "records.dat” for output?
A.
FileOut output;
output = new FileOut ("records. dat”);
B.
BufferedFileWriter output;
output = new BufferedFileWriter ("records. dat”);
C.
FileWriter output = new FileWriter ("records. dat”);
D.
FileStream output = new FileStream ("records. dat”);
Select one:
a.A
b.B
c.C
d.D
What is the value of minutes[2][4] in the following array?
int[][]minutes={ {12,23,45,33,52},
{54, 41, 29, 17, 35},
{11, 21, 44, 58, 31},
{25, 18, 46, 37, 57} };
Select one:
a. 17;
b. 18;
c. 31;
d. 46;
Which of the following multiplies the values in the 15th item and 20th item, and saves the result in the 25th element in an array named Total ?
Select one:
a. Total [25] = Total [15] * Total [20];
b. Total [24] = Total [14] * Total [19];
c. Total [14] * Total [19] = Total [24];
d. Total [15] * Total [20] = Total [25];
Which of the following statement divides the value of the 4th element by 3 and assigns the result to the 6th element in an array named Count ?
Select one:
a. Count[5] = Count[4] / 3;
b. Count[6] = Count[4] / 3;
c. Count[5] = Count[3] / 3;
d. Count[6] = Count[3] / 3;
What will be returned from the following method?
int Output()
{
int x = 7, y = 10;
if (x > 5 && y < 4)
return x - y;
else if (x < 5 || y > 4)
return x + y;
else
return x * y;
return -1;
}
Select one:
a. -3
b. 17
c. 70
d. -1
Given the void method:
void Fastest (double a, double b, double c);
Which of the following would be a valid method call? Select one:
a. Fastest (40, 60, 20);
b. Fastest (double x, double y, double z);
c. void Fastest (m, n, k);
d. void Fastest (40, 60, 20);
Explanation / Answer
1)What would a catch { } clause do in Java? Select one:
Answer is b. handle an exception and recover the program
the code is placed between try{} block and if there is any issue, an exception is thrown which is handled by catch{} block. each try block must be followed by atleast one catch block.
2)Which of the following statements would open a le named "records.dat” for output?
Answer is C. FileWriter output = new FileWriter ("records. dat”);
FileWriter constructor take filename as input and opens the file to write the data into it.
3) What is the value of minutes[2][4] in the following array?
Answer is c. 31;
minutes is a 2D array with 4 rows and 5 columns. array[x][y] is defined as 2d array with xth row and yth column. Note that in array positions start from 0, So minutes[2][4] means 3rd row 5th element which is 31.
4)Which of the following multiplies the values in the 15th item and 20th item, and saves the result in the 25th element in an array named Total ?
Answer is b. Total [24] = Total [14] * Total [19];
As , array indexes start from 0 so 15th element, 20th element and 25th element will be Total[14] ,Total[19] and Total[24] respectively. As per statement syntax, expression must be on right and the variable in which it should be assigned must be at left.
5)Which of the following statement divides the value of the 4th element by 3 and assigns the result to the 6th element in an array named Count ?
Answer is c. Count[5] = Count[3] / 3;
Explanation is as per the previous question.
6)What will be returned from the following method?
Answer is b. 17
the first if condition will be wrong as y is not less than 4 as it is 10. So control goes to next if condition . As ther is OR operator between the two conditions , So atleast one of the two must be true and y > 4 condition is true , so the function add two variables and return it.
7)Given the void method:
void Fastest (double a, double b, double c);
Which of the following would be a valid method call? Select one:
Answer is a. Fastest (40, 60, 20);
Because while calling the function , return type of function and datatype of members of function should not be given. in option a , neither return type is there nor the datatype of variables, just three ints are passed which are typecasted to double.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.