0% found this document useful (0 votes)
39 views4 pages

Cs2401 - Quiz 4 February 12, 2014 - 17 Questions / 20 Points / 20 Minutes NAME: .. Questions On Objects and Classes

This document contains a quiz on objects, classes, and multi-dimensional arrays in Java with 17 multiple choice questions. It provides the name of the quiz, date, number of questions and points, and time limit. The questions cover topics such as the differences between classes and objects, class declarations, constructors, and accessing elements in multi-dimensional arrays.

Uploaded by

Kiruba K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views4 pages

Cs2401 - Quiz 4 February 12, 2014 - 17 Questions / 20 Points / 20 Minutes NAME: .. Questions On Objects and Classes

This document contains a quiz on objects, classes, and multi-dimensional arrays in Java with 17 multiple choice questions. It provides the name of the quiz, date, number of questions and points, and time limit. The questions cover topics such as the differences between classes and objects, class declarations, constructors, and accessing elements in multi-dimensional arrays.

Uploaded by

Kiruba K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CS2401

 –  QUIZ  4  
February  12,  2014  –  17  questions  /  20  points  /  20  minutes  
NAME:  …………………………………………..  
 
Questions  on  Objects  and  Classes  
 
1 __________ represents an entity in the real world that can be
distinctly identified.

A. A class
B. An object
C. A method
D. A data field

2 _______ is a construct that defines objects of the same type.

A. A class
B. An object
C. A method
D. A data field

3 An object is an instance of a __________.

A. program
B. class
C. method
D. data

4 The keyword __________ is required to declare a class.

A. public
B. private
C. class
D. All of the above.

5 ________ is invoked to create an object.

A. A constructor
B. The main method
C. A method with a return type
D. A method with the void return type

6 Which of the following statements are true?

A. A default constructor is provided automatically if no constructors


are explicitly declared in the class.
B. At least one constructor must always be defined explicitly.
C. Every class has a default constructor.
D. The default constructor is a no-arg constructor.

7 Which of the following statements are true?

A. Multiple constructors can be defined in a class.


B. Constructors do not have a return type, not even void.
C. Constructors must have the same name as the class itself.
D. Constructors are invoked using the new operator when an object is
created.

Questions  on  Multi-­‐Dimensional  Arrays  

8 Which of the following statements are correct?

A. char[][] charArray = {'a', 'b'};


B. char[2][2] charArray = {{'a', 'b'}, {'c', 'd'}};
C. char[2][] charArray = {{'a', 'b'}, {'c', 'd'}};
D. char[][] charArray = {{'a', 'b'}, {'c', 'd'}};

9 Assume double[][] x = new double[4][5], what are x.length and


x[2].length?

A. 4 and 4
B. 4 and 5
C. 5 and 4
D. 5 and 5

10 What is the index variable for the element at the first row and
first column in array a?

A. a[0][0]
B. a[1][1]
C. a[0][1]
D. a[1][0]

11 How many elements are in the matrix (int[][] matrix = new


int[5][5])?

A. 14
B. 20
C. 25
D. 30

12 Analyze the following code:

public class Test {


public static void main(String[] args) {
boolean[][] x = new boolean[3][];
x[0] = new boolean[1]; x[1] = new boolean[2];
x[2] = new boolean[3];

System.out.println("x[2][2] is " + x[2][2]);


}
}

A. The program has a compile error because new boolean[3][] is wrong.


B. The program has a runtime error because x[2][2] is null.
C. The program runs and displays x[2][2] is null.
D. The program runs and displays x[2][2] is true.
E. The program runs and displays x[2][2] is false.
13 What will be displayed by the following program?

public class Test {


public static void main(String[] args) {
int[][] values = {{3, 4, 5, 1}, {33, 6, 1, 2}};

int v = values[0][0];
for (int row = 0; row < values.length; row++)
for (int column = 0; column < values[row].length; column++)
if (v < values[row][column])
v = values[row][column];

System.out.print(v);
}
}

A. 1
B. 3
C. 5
D. 6
E. 33

14 What will be displayed by the following program?

public class Test {


public static void main(String[] args) {
int[][] values = {{3, 4, 5, 1}, {33, 6, 1, 2}};

int v = values[0][0];
for (int[] list : values)
for (int element : list)
if (v > element)
v = element;

System.out.print(v);
}
}

A. 1
B. 3
C. 5
D. 6
E. 33

15 What is the output of 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] + " ");
}
}

A. 1 2 3 4
B. 4 5 6 7
C. 1 3 8 12
D. 2 5 9 13
E. 3 6 10 14

16 What will be displayed by the following program?

public class Test {


public static void main(String[] args) {
int[][] values = {{3, 4, 5, 1}, {33, 6, 1, 2}};

for (int row = 0; row < values.length; row++) {


System.out.print(m(values[row]) + " ");
}
}

public static int m(int[] list) {


int v = list[0];
for (int i = 1; i < list.length; i++)
if (v < list[i])
v = list[i];
return v;
}
}

A. 3 33
B. 1 1
C. 5 6
D. 5 33
E. 33 5

17 What will be displayed by the following code?

public class Test {


public static void main(String[] args) {
int[][][] data = {{{1, 2}, {3, 4}},
{{5, 6}, {7, 8}}};

System.out.print(data[1][0][0]);
}
}

A. 1
B. 2
C. 4
D. 5
E. 6

You might also like