CIS 3090 Final

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Which of the following statements is valid? a) int[ ] i = {"3", "4", "3". "5"}; b) int i = new int(30); c) double d[ ] = new double[30]; d) char [ ] c = new char( ); e) char [ ] c = new char[4] {'a','b','c','d'};

C

Which of the following statements is true? a) At least one constructor must always be defined explicitly b) Constructors are invoked using the (this) operator when an object is created c) Constructor does not have a return type, not even void d) You can only have one constructor per class

C) Constructor does not have a return type, not even void

Suppose the rule of the party is that the participants who arrive later will leave last. Which data structure is appropriate to store the participants? a) queue b) linked list c) array list d) stack

Queue

Which loop is a pretest that first initializes a counter variable and then automatically increments the counter variable at the end of each iteration?

The For... Next Loop

___ represents an entity in the real world that can be distinctly identified

an object

the default constructor has no argument

true

Given the declaration Circle x = new Circle( ), which of the following statement is most accurate.

x contains a reference to a Circle object.

Given the declaration Circle[ ] x = new Circle[10], which of the following statements is most accurate.

x contains a reference to an array and each element in the array can hold a reference to a Circle object.

Which method do you use to test if an element is a set or list named x? a) (elements instanceof List) || (elements instanceof Set) b) x.contains(element) c) x.in(element) d) x.contains(element) e) x.include(element)

x.contains(element)

Which method do you use to remove an element from a set or list named x?

x.remove(element)

___ is a constructor that denied object of the same type

a class

Given the following code that creates and initialize a Hash Map: HashMap<String, Integer> exMap = new HashMap<String, Integer>(); which of the following is a valid operation a) exMap.put("John", 5); b) exMap.add("John", 25); c) exMap.put("John", "5"); d) exMap.add("John", "5");

a) exMap.put("John", 5); (exMap.put is the correct operation)

Examine the following program code: int[] array = { 1, 4, 3, 6, 8, 2, 5}; int what = array[0]; // scan the array for ( int index=0; index < array.length; index++ ) { if ( array[ index ] < what ){ what = array[ index ]; } } System.out.println( what ); What does the code print to the screen?

1

What is y after the following for loop statement is executed? int y = 0; for (int i = 0; i < 10; ++ i) { y += 1; }

10

What is the output of the following fragment? the condition of the loop is that i is less than 5 int i = 1; int j = 1; while (condition) { i++ ; j = j * 2; } System.out.println(j);

16

[9][4][12][2][6][8][18] What is returned by values[3]?

2

________ is a data structure to store data in sequential order. A) set B) list C) stack D) vector

A list

[9][4][12][2][6][8][18] What is the value of values.length

7

Examine the following program code: int[] array = { 1, 4, 3, 6, 8, 2, 5}; int what = array[0]; // scan the array for ( int index=0; index < array.length; index++ ) { if ( array[ index ] > what ){ what = array[ index ]; } } System.out.println( what ); What does the code print to the screen?

8

Fill in the code in ArrayList _______ studentList = new ArrayList< Student> ( );

<Student>

________ is invoked to create an object.

A Constructor

How can you initialize an array of two characters to 'a' and 'b'? A. char[] charArray = new char(){'a','b'}; B. char[2] charArray = {'a', 'b'}; C. char[] charArray = {'a', 'b'}; D. char[] charArray = new char[2]; charArray = {'a', 'b'};

C. char[ ] charArray = {'a', 'b'}; (also acceptable: char[ ] charArray = new char[ ]{'a', 'b'};)

Suppose int i = 5, double j =6.5 which of the following can be used as an index for array double[] t = new double[100]?

C. i + 10 (alternative answers) i (int)(Math.random() * 10))

Which of the data type below does not allow duplicates? a) Vector b) Stack c) List d) Set e) LinkedList

D) Set

Java methods can return only primitive types (int, double, boolean, etc).

False

You can always use the default constructor even though the non-default constructor is defined in the class

False

Consider the array declaration and instantiation: int[ ] arr = new int[5]; Which of the following is true about arr?

It stores 5 elements with legal indices between 0 and 4

To initialize a String array names to store the three Strings "Huey", "Duey" and "Louie", you would do

String[] names = {"Huey", "Duey", "Louie"};

Which of the following is a legal way to declare and instantiate an array of 10 String?

String[]s = new String[10];

Analyze the following code public class Test { public static void main(String[ ] args) { int n = 2; xMethod(n); System.out.println("n is " + n); } void xMethod(int n) { n++ ; } }

The code has a syntax error because xMethod is not declared static

What balance after the following code is executed? int balance = 10; while (balance >= 1) { if (balance < 9) continue; balance = balance - 9; }

The loop does not end

Analyze the following code. public class Test { public static void main(String[ ] args) { int[ ] x = new int[3]; System.out.println("x[0] is " + x[0]); } }

The program runs find and displays x[0] = 0

Which of the following data type below could be used to store elements in the order they are added? a) HashSet b) TreeMap c) Collection d) LinkedMap e) HashMap

TreeMap

A constructor must have the same name as its class.

True

What is wrong in the following program? class Test { public static void main (String[ ] args) { try { System.out.println("Welcome to Java"); } } }

You cannot have a try block without a catch block or a finally block.

[9][4][12][2][6][8][18] The statement System.out.println(values[7]); will

cause an ArrayOutOfBoundsException to be thrown

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'}};

char[][] charArray = {{'a', 'b'}, {'c', 'd'}};

An object is an instance of a

class

The Keyword is required to declare a class

class

Suppose a method p has the following heading: public static int[ ] p( ) What return statement may be used in p( )?

return new int[ ]{1, 2, 3};


Ensembles d'études connexes

imunology general mcq to sort out

View Set

EC350: Firms in Perfectly Competitive Markets

View Set

Earth Science 113/114B - Unit 1 Study Guide

View Set

ATI- Pharm Made Easy- Cardiovascular Questions

View Set

Chapter 21: Somatic Symptom Illnesses (COMBINED)

View Set