Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
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. In Eclipse, when you run a Java Application, where may the results display? Mark for Review (1) Points Editor Window Console View (*) Debug View Task List None of the above Correct 2. What are the Eclipse Editor Area and Views used for? Mark for Review (1) Points (Choose all correct answers) To modify elements. (*) To navigate a hierarchy of information. (*) To choose the file system location to delete a file. Correct 3. A combination of views and editors are referred to as _______________. Mark for Review (1) Points A workspace A physical location A perspective (*) All of the above Correct 4. In the image below, identify the components. Mark for Review (1) Points A-Main Method, B-Class, C-Package A-Class, B-MainMethod, C-Package A-Package, B-Main Method, C-Class (*) None of the above Correct 5. A counter used in a For loop cannot be initialized within the For loop header. 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. In the code fragment below, the syntax for the for loop's initialization is correct. True or false? public class ForLoop { public static void main (String args[]) { for ((int 1=10) (i<20) (i++))< {System.out.Println ("i: "+i); } } } Mark for Review (1) Points True False (*) Correct 7. When importing another package into a class you must import only the package classes that will be called and not the entire package. True or false? Mark for Review (1) Points True False (*) Correct 8. Which of the two diagrams below illustrate the correct syntax for variables used in an if-else statement? Mark for Review (1) Points Example A (*) Example B Correct 9. What are Java's simple types? Mark for Review (1) Points boolean, byte, char, double, float, int, long, and short (*) boolean, byte, string, thread, int, double, long and short object, byte, string, char, float, int, long and short boolean, thread, stringbuffer, char, int, float, long and short boolean, thread, char, double, float, int, long and short Correct 10. Select the declaration and initialization statement that will hold the letter J. Mark for Review (1) Points int letter='J'; float letter='J'; String letter='J'; char letter='J'; (*) Correct 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. Which of the following are relational operators in Java? Mark for Review (1) Points (Choose all correct answers) < (*) <= (*) = != (*) All of the above. Correct 12. What is the output of the following lines of code? int j=6,k=4,m=12,result; result=j/m*k; System.out.println(result); Mark for Review (1) Points 2 0 (*) 48 24 Correct 13. Which of the following is the name of a Java primitive data type? Mark for Review (1) Points Object Rectangle double (*) String Correct 14. The three logic operators in Java are: Mark for Review (1) Points &&, ||, ! (*) !=,=,== &&,!=,= &,|,= Correct 15. The six relational operators in Java are: Mark for Review (1) Points >,<,=,!,<=,>= >,<,==,!=,<=,>= (*) >,<,=,!=,<=,>= >,<,=,!=,=<,=> 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 16. All of the following are essential to initializing a FOR loop, except which one? Mark for Review (1) Points Initializing the iterator(i). Having a conditional statement. Updating the counter. Having an if statement. (*) Correct 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 (*) False Correct 18. What is the output of the following code segment? int num = 7; while(num >= 0) { num -= 3; } System.out.println(num); Mark for Review (1) Points -2 (*) 1 0 2 Correct 19. Why are loops useful? Mark for Review (1) Points They save programmers from having to rewrite code. They allow for repeating code a variable number of times. They allow for repeating code until a certain argument is met. All of the above. (*) Incorrect. Refer to Section 5 Lesson 1. 20. 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(); Incorrect. Refer to Section 5 Lesson 2. 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 5 21. A class can only have one constructor. True or false? Mark for Review (1) Points True False (*) Correct 22. What value will return for j when the setValue method is called? Mark for Review (1) Points 31 32 10 11 (*) Correct 23. The following statement compiles and executes. What do you know for certain? tree.grows(numFeet); Mark for Review (1) Points numFeet must be an int. tree must be the name of the class. grows must be the name of an instance field. grows must be the name of a method. (*) tree must be a method. Correct 24. The following code creates an Object of type Animal. True or false? Animal a=new Animal(); Mark for Review (1) Points True (*) False Correct 25. The following code creates an Object of type Horse. True or false? Whale a=new Whale(); Mark for Review (1) Points True False (*) Correct 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 5 26. The following code is a good example of using the this reference. True or false? Mark for Review (1) Points True False (*) Correct Section 6 27. The following array declaration is valid. True or false? int[] y = new int[5]; Mark for Review (1) Points True (*) False Correct 28. What is the output of the following segment of code? Mark for Review (1) Points 456789 777777 (*) 555555 987654 This code doesn't compile. Correct 29. 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[]; (*) Incorrect. Refer to Section 6 Lesson 1. 30. 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. 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 6 31. Consider the following code snippet String forest = new String("Black"); System.out.println(forest.length()); What is printed? Mark for Review (1) Points 5 (*) 6 7 Black Forest Correct 32. Which of the following creates a String named Char? Mark for Review (1) Points char string; String Char; (*) char Char; char char; String char; Correct 33. The following code is an example of a correct initialization statement: char c="c"; Mark for Review (1) Points True False (*) Correct 34. The == operator can be used to compare two String objects. The result is always true if the two strings are have the exact same characters in each position of the String. True or false? Mark for Review (1) Points True False (*) Correct 35. Which of the following could be a reason to throw an exception? Mark for Review (1) Points To eliminate exceptions from disrupting your program. (*) You have a fatal error in your program. You have encountered a Stack Overflow Error. To make the user interface harder to navigate. Correct 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 6 36. Which of the following correctly matches the symbol with its function? Mark for Review (1) Points (Choose all correct answers) == (two equal signs) compares values of primitive types such as int or char. (*) == (two equal signs) compares the values of non-primitive objects. == (two equal signs) compares the memory location of non-primitive objects. (*) = (single equals sign) compares the value of primitive types such as int or char. .equals() compares the value of non-primitive objects. (*) Correct 37. If an exception is thrown by a method, where can the catch for the exception be? Mark for Review (1) Points There does not need to be a catch in this situation. The catch must be in the method that threw the exception. The catch can be in the method that threw the exception or in any other method that called the method that threw the exception. (*) The catch must be immediately after the throw. Incorrect. Refer to Section 6 Lesson 3. 38. Suppose you are writing a program where the user is prompted to the give coordinates where they believe the princess is inside of the castle. Your program moves the prince to the coordinates that the user specified. If the princess is not found at those coordinates, the user is given a clue that helps them guess coordinates closer to the princess. The user is allowed to enter their new guess of where the princess is. Assume your program does not take into consideration the possibility that the user may enter coordinates outside of the castle where the princess could not be. What would be the result of the user entering coordinates outside of the castle? How could this be handled in your code? Mark for Review (1) Points (Choose all correct answers) An error would occur. Errors cannot be handled by code. An exception would occur but could not be handled inside your code. The user would have to restart the program and enter proper coordinates. An exception would occur. This could be handled by throwing the exception in your code if the user enters invalid coordinates. When the exception is caught, the prince could be moved to the coordinate inside the castle that is closest to those that the user specified. (*) An exception would occur. This could be handled by throwing an exception in your code if the user enters invalid coordinates. When the exception is caught, the user could be prompted to enter coordinates within the given range of the castle. (*) Incorrect. Refer to Section 6 Lesson 3. Section 7 (Answer all questions in this section) 39. 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 Incorrect. Refer to Section 7 Lesson 3. 40. 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 3. 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 is the Java Applet? Mark for Review (1) Points (Choose all correct answers) It is the virtual machine that translates Java code into a representation that the computer can understand. A web-based Java program that is embedded into a web browser. (*) A graphic visual included in Java. (*) There is no such thing as a Java Applet. Incorrect. Refer to Section 7 Lesson 3. 42. Which segment of code represents a correct way to define a variable argument method? Mark for Review (1) Points String easyArray(String... elems) {//code} (*) String easyArray(...String elems) {//code} String... easyArray(String elems) {//code} Integer easyArray... (int elems) {//code} Correct 43. Which of the following is the correct way to code a method with a return type an object Automobile? Mark for Review (1) Points Automobile upgrade(String carA){ carA="Turbo"; return carA;} Automobile upgrade(Automobile carA){ carA.setTurbo("yes"); return carA;} (*) String upgrade(String carA){ carA="Turbo"; return carA;} upgrade(Automobile carA) Automobile{ carA.setTurbo("yes"); return carA;} None of the above. It is not possible to return an object. Correct 44. Choose the correct implementation of a public access modifier for the method divide. Mark for Review (1) Points divide(int a, int b, public) {return a/b;} public divide(int a, int b) {return a/b;} (*) divide(int a, int b) {public return a/b;} divide(public int a, public int b) {return a/b;} Correct 45. Static methods can read instance variables. True or false? Mark for Review (1) Points True False (*) 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 (Answer all questions in this section) 46. Static methods can write to class variables. True or false? Mark for Review (1) Points True (*) False Incorrect. Refer to Section 7 Lesson 2. 47. A static variable is always publicly available. True or false? Mark for Review (1) Points True False (*) Correct 48. Abstract classes cannot implement interfaces. True or false? Mark for Review (1) Points True False (*) Incorrect. Refer to Section 7 Lesson 4. 49. If Oak extends Tree, it is possible to declare an object such that Tree grandfatherT = new Oak(); True or false? Mark for Review (1) Points True (*) False Correct 50. Abstract class cannot extend another abstract class. True or false? Mark for Review (1) Points True False (*) Correct Previous Page 10 of 10 Summary