Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Can two different classes contain methods with the same name? A. No. B. Yes, but only if the two classes have the same name.

1. Can two different classes contain methods with the same name?

A. No.

B. Yes, but only if the two classes have the same name.

C. Yes, but only if the main program does not create objects of both kinds.

D. Yes, this is always allowed.

2. What is the primary purpose of a constructor?

A. To allow multiple classes to be used in a single program.

B. To copy an actual argument to a method's parameter.

C. To initialize each object as it is declared.

D. To maintain a count of how many objects of a class have been created.

3. Consider this class definition:

public class Quiz

{

private double score;

public int f( )...

public static int g( )...

}

Where could the assignment score=1.0; appear for the private instance variable score?

A. Both f and g can carry out the assignment.

B. f can carry out the assignment, but not g.

C. g can carry out the assignment, but not f.

D. Neither f nor g can carry out the assignment.

4. Suppose we have this method:

public static foo(int[ ] b){

b[0]++; }

What is printed by these statements?

int[ ] x = new int[100];

x[0] = 2;

foo(x);

System.out.println(x[0]);

A. 0

B. 1

C. 2

D. 3

5. Stacks operate as _______________.

A. Last Out, Last Out

B. First In, First Out

C. Last In, First Out

D. None of the above

6. A ______ can be used to reverse the order of a set of data.

Queue

Stack

Software

Heaps

7. I have an array named data, which contains n integers. I want to print all of the numbers, starting at data[0]. BUT if the number 42 occurs, then I want to stop my printing just before the 42 (without printing the 42!) Here is most of my for-loop to accomplish my goal:

for (i = 0; ___________________________________________; i++)

System.out.println(data[i]);

What is the correct way to fill in the blank? (If there is more than one correct answer, please select E.)

A. (data[i] != 42) && (i < n)

B. (data[i] != 42) || (i < n)

C. (i < n) && (data[i] != 42)

D. (i < n) || (data[i] != 42)

E. More than one of the above answers is correct

8. Analyze the following code. int count = 0; while (count < 100) { // Point A System.out.println("Welcome to Java!"); count++; // Point B } // Point C

A. count < 100 is always false at Point A

B. count < 100 is always true at Point B

C. count < 100 is always false at Point C

D. count < 100 is always true at Point C

E. count < 100 is always false at Point B

9. To add an element to a stack you use the method.

A. push

B. pop

C. peek

D. size

10. What is y after the following switch statement is executed?

x = 3;

switch (x + 3) {

case 6: y = 0;

case 7: y = 1;

default: y += 1;

}

a. 1

b. 4

c. 3

d. 2

e. 0

True/False (4 points each)

11. True/False. An array dynamically grows as needed and essentially has no capacity limitations.

12. True/False. If the algorithm is inefficient, a faster processor will make it very efficient.

13. True/False. A linked list has no set capacity limitations other than the size of the computers memory.

14. True/False. A singly linked list maintains a reference to the first element in the list and then a next reference from each node to the following node in the list.

15. True/False. Postfix notation avoids the need for precedence rules that are required to evaluate infix expressions.

16. True/False An abstract data type is a data type that is not defined within the programming language and must be defined by the programmer.

17. True/False. The new operator returns a reference to a newly created object.

18. True/False. Objects should be encapsulated. The rest of a program should interact with an object only through a well-defined interface.

19. True/False. Instance variables should be declared with public visibility to promote encapsulation.

20. True/False. A constructor cannot have any return type, even void.

21. True/False. A class is the implementation of the blueprint for an object. An object is a specific instance of a class.

22. True/False. Overloaded methods are distinguished from each other by their signatures including the number and type of the parameters.

Fill in the blank (short answer): (4 points each)

23. What are the five basic operations on a stack?

24. What are the 3 primary methods for a stack?___________________________

25. Here is a method with a parameter named spot, which is an integer:

public static foo(int spot)

{

spot += 2;

}

Now, suppose that s is an integer with a value of 40. Then the method foo(s) is activated. What is the value of s after this activation?

26. Convert the following to postfix expression

(9+2) / (6*7 2)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

Students also viewed these Databases questions

Question

OUTCOME 1 Explain the reasons for equity-related legislation.

Answered: 1 week ago