Exam 2 MC

Exam 2 MC

10th - 12th Grade

10 Qs

quiz-placeholder

Similar activities

AP CSA Arrays

AP CSA Arrays

10th - 12th Grade

14 Qs

Exploring Computer Science

Exploring Computer Science

10th - 12th Grade

14 Qs

Traversing Arrays

Traversing Arrays

10th - 12th Grade

14 Qs

Array Intro

Array Intro

9th - 12th Grade

7 Qs

J277 - 10QQ - Basic Python 1

J277 - 10QQ - Basic Python 1

8th - 10th Grade

10 Qs

Arrays

Arrays

10th - 12th Grade

10 Qs

String pada Java

String pada Java

12th Grade

15 Qs

Intro to Programming: data types, if/else, and loops

Intro to Programming: data types, if/else, and loops

8th - 12th Grade

15 Qs

Exam 2 MC

Exam 2 MC

Assessment

Quiz

Computers

10th - 12th Grade

Medium

Created by

Adam Lueken

Used 11+ times

FREE Resource

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Consider the Animal, Fish, and Goldfish classes shown below. Which of the following object declarations will compile without error?

public class Animal

{

/* no constructors or other methods have been declared */

}


public class Fish extends Animal

{

/* no constructors or other methods have been declared */

}


public class Goldfish extends Fish

{

/* no constructors or other methods have been declared */

}


I. Goldfish glub = new Fish();


II. Animal glub = new Fish();


III. Fish glub = new Goldfish();

(A) I only

(B) II only

(C) III only

(D) I and II only

(E) II and III only

2.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Assume that list has been instantiated as an ArrayList of integers containing [6, 2, 9] . What are the contents of list after the code is executed?

list.remove(2);

list.add(1, 4);

list.add(5);

list.set(2, 7);

(A) [6, 2, 7, 5]

(B) [6, 4, 2, 7, 5]

(C) [4, 7, 9, 5]

(D) [6, 4, 7, 5]

(E) [4, 7, 6, 9, 5]

3.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

A sorted array of integers containing 2000 elements is to be searched for key using a binary search method. Assuming key is in the array, what is the maximum number of iterations needed to find key?

(A) 8

(B) 10

(C) 100

(D) 2000

(E) 11

4.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Which of the following code segments creates a 7 x 9 array of integers and fills every space in the array with multiples of two (not including the value 0)?

I. int[][] arr = new int [7][9];


II. int[][] arr = new int [7][9];

int count = 1;


for(int i = 0; i < arr.length; i++)

{

for(int j = 0; j < arr[0].length; j++)

{

arr[i][j] = count * 2;

count++;

}

}


III. int[][] arr = new int [7][9];

int count = 1;

int row = 0;

int col = 0;


while (row < arr.length && col < arr[0].length)

{

arr[row][col] = count * 2;

row++;

col++;

count++;

}

(A) I only

(B) II only

(C) II and III only

(D) I and II only

(E) III only

5.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Consider the method printString shown below. What is printed as a result of printString(“sandwich”)?

public void printString(String s)

{

if (s.length() > 0)

{

printString(s.substring(1));

System.out.print(s.substring(0, 1));

}

}

(A) hciwdnas

(B) sandwich

(C) andwichandwichndwichdwichwichichchh

(D) hchichwichdwichndwichandwich

(E) Nothing is printed because an infinite loop occurs

6.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

The Dog class is shown below. The GoldenRetriever class inherits from the Dog class. Which methods and variables does the GoldenRetriever class inherit?

public class Dog

{

private int numLegs = 4;

private String name = "Spot";


public Dog(String theName)

{

/* implementation not shown */

}


public String bark()

{

return "Woof!";

}


public String getName()

{

return name;

}


public int getNumLegs()

{

return numLegs;

}

}


I. public Dog(String theName)


II. bark()


III. getName()


IV. private String name;

(A) I only

(B) I and II only

(C) III only

(D) II and III only

(E) I, II, III, and IV

7.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Which of these loops will output 02468?

I. for (int i = 0; i <= 8; i++)

{

System.out.print(i);

}


II. int i = 0;

while (i < 8)

{

i +=2;

System.out.print(i);

}


III. for (int i = 0; i <= 8; i +=2)

{

System.out.print(i);

}

(A) I only

(B) II only

(C) III only

(D) I and II only

(E) I, II, and III

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?