• No results found

Java Final Exam

N/A
N/A
Protected

Academic year: 2021

Share "Java Final Exam"

Copied!
15
0
0

Loading.... (view fulltext now)

Full text

(1)

Test: Java Fundamentals Final Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 4

(Answer all questions in this section)

1. Which of the following declarations are correct?

Mark for Review

(1) Points (Choose all correct answers)

double duty; (*) float loan; (*) boolean value = 12; int start = 34, 3nd = 99;

Correct

2. Which line of Java code will assign the value of the square root of 11 to a variable

named a? Mark for Review

(1) Points double a=11^(1/2); double a=sqrt(11); int a=Math.sqrt(11); double a=Math.sqrt*11; double a=Math.sqrt(11); (*) Correct

3. The ______________ is the location into which you will store and save your files.

Mark for Review

(1) Points Perspective

Workspace (*) Editor

None of the above Correct

4. A workspace is:

Mark for Review

(1) Points The physical location onto which you will store and save your files.

The location where all projects are developed and modified. The location where you can have one or more stored perspectives. All of the above. (*)

(2)

5. A workspace can not have more than one stored projects. True or false?

Mark for Review

(1) Points True

False (*) Correct

Page 1 of 10

Next Summary

Test: Java Fundamentals Final Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 4

(Answer all questions in this section)

6. You can return to the Eclipse Welcome Page by choosing Welcome from what menu?

Mark for Review

(1) Points File Edit Help (*) Close Correct

7. A perspective is described as:

Mark for

Review

(1) Points A combination of views and editors (*)

A combination of views and windows A combination of editor tabs

None of the above

Incorrect. Refer to Section 4 Lesson 1.

8. Which of the following defines a driver class?

Mark for

Review

(1) Points Contains a main method and other static methods. (*)

Contains classes that define objects.

(3)

None of the above.

Incorrect. Refer to Section 4 Lesson 2.

9. Which of the following defines an object class?

Mark for

Review

(1) Points Contains a main method and other static methods.

Contains classes that define objects. (*)

Contains a main method, a package, static methods, and classes that define objects. None of the above.

Correct

10.

Consider the following code snippet.

What is printed? Mark for Review

(1) Points 88888 (*) 88888888 1010778 101077810109 ArrayIndexOutofBoundsException is thrown Incorrect. Refer to Section 4 Lesson 4.

Previous

Page 2 of 10

Next Summary

Test: Java Fundamentals Final Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 4

(Answer all questions in this section)

11.

Consider the following code snippet. Mark for

Review

(4)

What is printed? Cayrbniz CayrbnizCayrbniz yr (*) ay ArrayIndexOutofBoundsException is thrown Incorrect. Refer to Section 4 Lesson 4.

12.Given the code:

String s = new String("abc");

Which of the following statements will change the length of s to the largest length?

Mark for Review

(1) Points s.trim() s.replace("a", "aa") s.substring(2) s.toUpperCase()

None of the above will change the length of s. (*) Correct

13.What is printed by the following code segment?

Mark for Review

(1) Points \\\\ \\\\\\\ (*) \\\\\\\\\\\\\\ \\ Correct

(5)

14.The following code is an example of creating a String reference: String s; True or false? Mark for Review

(1) Points True (*) False Correct Section 5

(Answer all questions in this section)

15.

How many times will the following loop be executed? What is the value of x after the loop has finished?

What is the value of count after the loop has finished? int count = 17; int x = 1; while(count > x){ x*=3; count-=3; } Mark for Review

(1) Points 4; 8; 27 3; 27; 8 (*) 5; 27; 8 5; 30; 5 3; 9; 11 Correct

Previous

Page 3 of 10

Next Summary

Test: Java Fundamentals Final Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 5

(Answer all questions in this section)

16. One advantage to using a while loop over a for loop is that a while loop always has a

counter. True or false? Mark for Review

(1) Points True

False (*)

Incorrect. Refer to Section 5 Lesson 2.

17. Updating the input of a loop allows you to implement the code with the next element

rather than repeating the code always with the same element. True or false? Mark for Review

(1) Points True (*)

(6)

False Correct

18. Which of the following could be a reason to use a switch statement in a Java program?

Mark for Review

(1) Points Because it allows the code to be run through until a certain conditional statement

is true.

Because it allows the program to run certain segments of code and neglect to run others based on the input given. (*)

Because it terminates the current loop.

Because it allows the user to enter an input in the console screen and prints out a message that the user input was successfully read in.

Correct

19. Determine whether this boolean expression evaluates to true or false:

!(3<4&&6>6||6<=6&&7-2==6)

Mark for Review

(1) Points True (*)

False

Incorrect. Refer to Section 5 Lesson 1.

20. How would you use the ternary operator to rewrite this if statement?

if (balance < 500)< fee = 10;

else fee = 0;

Mark for Review

(1) Points fee = ( balance < 500) ? 0 : 10; fee= ( balance < 500) ? 10 : 0; (*) fee = ( balance >= 5) ? 0 : 10; fee = ( balance >= 500) ? 10 : 0; fee = ( balance > 5) ? 10 : 0;

Incorrect. Refer to Section 5 Lesson 1.

Previous

Page 4 of 10

Next Summary

Test: Java Fundamentals Final Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 6

(Answer all questions in this section)

21. Which of the following declares a one dimensional array name scores of type int that

can hold 14 values? Mark for Review

(7)

int scores;

int[] scores=new int[14]; (*) int[] scores=new scores int[14]; int score= new int[14];

Incorrect. Refer to Section 6 Lesson 1.

22. What is the output of the following segment of code?

int array[][] = {{1,2,3},{3,2,1}}; for(int i=0;i<2;i++)

for(int j=0;j<3;j++)

System.out.print(2*array[1][1]);

Mark for Review

(1) Points

444444 (*) 123321 246642 222222

This code doesn't compile.

Incorrect. Refer to Section 6 Lesson 1.

23. Which of the following declares and initializes a one dimensional array that can hold 5

Object reference types? Mark for Review

(1) Points String[] array=new String[5];

Object array=new Object[5]; (*) Object[] array=new Object[4]; String[] array=String[4];

Incorrect. Refer to Section 6 Lesson 1.

24. Which of the following statements is not a valid array declaration?

Mark for Review

(1) Points int number[]; float []averages; double marks[5]; counter int[]; (*) Correct

25. Which of the following is a sorting algorithm that involves repeatedly incrementing

through the array and swapping 2 adjacent values if they are in the wrong order until all elements are in the correct order?

Mark for Review

(1) Points Selection Sort

(8)

Bubble Sort (*) Sequential Search Binary Search

Incorrect. Refer to Section 6 Lesson 2.

Previous

Page 5 of 10

Next Summary

Test: Java Fundamentals Final Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 6

(Answer all questions in this section)

26. Which of the following is the correct lexicographical order for the conents of the int

array?

{17, 1, 1, 83, 50, 28, 29, 3, 71, 22}

Mark for Review

(1) Points {71, 1, 3, 28,29, 50, 22, 83, 1, 17} {83, 71, 50, 29, 28, 22, 17, 3, 1, 1} {1, 1, 17, 22, 28, 29, 3, 50, 71, 83} {1, 2, 7, 0, 9, 5, 6, 4, 8, 3} {1, 1, 3, 17, 22, 28, 29, 50, 71, 83} (*) Correct

27. Which searching algorithm involves using a low, middle, and high index value to find

the location of a value in a sorted set of data (if it exists)? Mark for Review

(1) Points Sequential Search

Merge Sort Selection Sort Binary Search (*) All of the above

Incorrect. Refer to Section 6 Lesson 2.

28. Big-O Notation is used in Computer Science to describe the performance of Sorts and

Searches on arrays. True or false? Mark for Review

(1) Points True (*)

False

Incorrect. Refer to Section 6 Lesson 2.

29. A logic error occurs if an unintentional semicolon is placed at the end of a loop

initiation because the interpreter reads this as the only line inside the loop, a line that does nothing. Everything that follows the semicolon is interpreted as code outside of the loop. True or false?

Mark for Review

(9)

True False (*)

Correct

Section 7

(Answer all questions in this section)

30. If a variable in a superclass is private, could it be directly accessed or modified by a

subclass? Why or why not? Mark for Review

(1) Points Yes. A subclass inherits full access to all contents of its super class.

Yes. Any variable passed through inheritance can be changed, but private methods cannot.

No. A private variable can only be modified by the same class with which it is declared regardless of its inheritance. (*)

No. Nothing inherited by the super class can be changed in the subclass. Correct

Previous

Page 6 of 10

Next Summary

Test: Java Fundamentals Final Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 7

(Answer all questions in this section)

31. Which of the following is the correct way to call an overriden method needOil() of a

super class Robot in a subclass SqueakyRobot? Mark for Review

(1) Points Robot.needOil(SqueakyRobot);

SqueakyRobot.needOil(); super.needOil(); (*) needOil(Robot);

Incorrect. Refer to Section 7 Lesson 4.

32. An access modifier is a keyword that allows subclasses to access methods, data, and

constructors from their parent class. True or false? Mark for Review

(1) Points True (*)

False Correct

33. What is encapsulation?

Mark for Review

(1) Points A keyword that allows or restricts access to data and methods.

(10)

exiting code for new applications.

A structure that categorizes and organizes relationships among ideas, concepts of things with the most general at the top and the most specific at the bottom. A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods. (*)

Correct

34. Any instance of the same class can assign a new value to a static variable. True or

false? Mark for Review

(1) Points True (*)

False Correct

35. Static methods can change instance variables at run-time. True or false?

Mark for Review

(1) Points True

False (*)

Incorrect. Refer to Section 7 Lesson 3.

Previous

Page 7 of 10

Next Summary

Test: Java Fundamentals Final Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 7

(Answer all questions in this section)

36.

A base case can handle nested conditions. True or false? Mark for

Review

(1) Points True (*) False Correct 37.

If we override the toString() method with the code below, what would be the result of

printing? Mark for

Review

(11)

It would print the array one element at a time. The console screen would display: 0 18 215 64 11 42

It would print the string returned from the method. The console screen would display: [0,18,215,64,11,42,] (*)

It would print the array backwards. The console screen would display: 42 11 64 215 18 0

It would print the string returned from the method. The console screen would display: {0, 18, 215, 64, 11, 42}

Correct

38.

Identify the correct way to declare an abstract class. Mark for

Review

(1) Points abstract public class ClassName{...}

public abstract ClassName(...) public class abstract ClassName(...) public abstract class ClassName{...} (*)

Incorrect. Refer to Section 7 Lesson 5.

39.

If a class is immutable then it must be abstract. True or false? Mark for

Review

(1) Points True

False (*)

Incorrect. Refer to Section 7 Lesson 5.

40.

A class can only have one constructor. True or false?

Mark for

Review

(1) Points True

False (*)

Incorrect. Refer to Section 7 Lesson 1.

Previous

Page 8 of 10

Next Summary

Test: Java Fundamentals Final Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 7

(Answer all questions in this section)

41.

What value will return for j when the setValue method is called? Mark for

Review

(12)

31 32 10 11 (*)

Incorrect. Refer to Section 7 Lesson 1.

42.

What is the output of the following code segment: int n = 13;

System.out.print(doNothing(n)); System.out.print(" ", n);

where the code from the method doNothing is: public double doNothing(int n)

{ n = n + 8; return (double) 12/n; } Mark for Review

(1) Points 1.75, 13 0.571, 21 1.75, 21 0.571, 13 (*)

Incorrect. Refer to Section 7 Lesson 1.

43.

What is true about the code below: Car car1=new Car();

Car car2=new Car(); car2=car1;

Mark for

Review

(1) Points (Choose all correct answers)

The references car1 and car2 are pointing to two Car Objects in memory.

(13)

There are no more Car objects in memory.

There is a Car object that car1 referenced that is now slated for removal by the garbage collector.

There is a Car object that car2 referenced that is now slated for removal by the garbage collector. (*)

Incorrect. Refer to Section 7 Lesson 1.

44.

Which of the following calls the method calculate correctly? Mark for

Review

(1) Points

ThisClass t=new ThisClass(); int x=t.calculate(3,4); (*) int x=calculate(3,4);

ThisClass t=new ThisClass(); int x=t.calculate(3); ThisClass t=new ThisClass(); int x=t.calculate();

Correct

45.

What is wrong with the following class declaration? class Account{ ;

private int number; private String name;; public Account; }

Mark for

Review

(1) Points

Classes cannot include strings.

Classes cannot include mixed data types. The constructor method has no definition. (*) There is nothing wrong.

Correct

Previous

Page 9 of 10

Next Summary

Test: Java Fundamentals Final Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 7

(14)

46. Which of the following specifies accessibility to variables, methods, and classes?

Mark for Review

(1) Points Methods Parameters Overload constructors Access modifiers (*) Correct

47. Which of the following correctly defines overloading?

Mark for Review

(1) Points Having more than one constructor with the same name but different arguments.

(*)

Having more than one constructor with different names and the same arguments. A variable argument method that returns an array.

A type of access specifier that only allows access from inside the same class. Incorrect. Refer to Section 7 Lesson 2.

48. Which of the following is the correct definition of a parameter?

Mark for Review

(1) Points A keyword that specifies accessibility of code.

A way to call a method with a variable number of arguments using an elipse. A variable in a method declaration that gets passed into the method. (*) A type of access specifier.

It is used to assign initial values to instance variables of a class; the structure is very similar to that of a method.

Correct

49. Which segment of code represents a correct way to call a variable argument method

counter that takes in integers as its variable argument parameter? Mark for Review

(1) Points counter(String a, int b);

counter(int[] numbers);

counter(1, 5, 8, 17, 11000005); (*) counter("one","two",String[] nums);

Incorrect. Refer to Section 7 Lesson 2.

50. Which of the following is the definition of a constructor?

Mark for Review

(1) Points A keyword that specifies accessibility of code.

A special method that is used to assign initial values to instance variables in a class. (*)

(15)

A way to call a method with a variable number of arguments using an elipse. A variable in a method declaration that gets passed into the method.

Incorrect. Refer to Section 7 Lesson 2.

References

Related documents

In the case of commercial piracy, the existence or nonexistence of piracy comes out as an endogenous outcome of the strategic game between the pirate and the original software firm;

While i t was improper for respondent to preside over cases in which his current or former clients were parties or.. attorneys, i t does not seem that such conduct must be repeated

A randomized, open-label, phase II study of everolimus in combination with pasireotide LAR or everolimus alone in advanced, well-differentiated, progressive pancreatic

Site earthing is required for all sizes of storage vessel, when the installation is fitted with electrical equipment, the primary requirement being protection against electric

would not be prudent to ignore the issue either with respect to long term trusts created in one of those 

(c) This Standard introduces requirements and tests for winding withstand capability. See Clause 6.2, Short-circuit withstand capability. See Clause 6.1.1, Rated insulation

injection rate at source node and actual acceptance rates at multicast target nodes for multicast communication 1, 2, 3 and 4 by using tree-based multicast router with static XY

how information exchange between whom at what stage in the process using which data