Practice Quiz for test_ JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF 2.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF Practice Quiz for test Due Oct 24 at 11:59p.m. Points 42 Questions 42 Available Oct 11 at 12a.m. - Oct 24 at 11:59p.m. Time Limit None All...

10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF Practice Quiz for test Due Oct 24 at 11:59p.m. Points 42 Questions 42 Available Oct 11 at 12a.m. - Oct 24 at 11:59p.m. Time Limit None Allowed Attempts 3 Take the Quiz Again Attempt History Attempt Time Score KEPT Attempt 2 42 minutes 35 out of 42 LATEST Attempt 2 42 minutes 35 out of 42 Attempt 1 71 minutes 33 out of 42 Submitted Oct 16 at 10:54p.m.  Question 1 1 / 1 pts  The extension name of a Java source code file is ________..obj.class.exe Correct!.java  Question 2 1 / 1 pts Java compiler translates Java source code into ________. Correct! Java bytecode assembly code another high-level language code machine code  Question 3 0 / 1 pts https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 1/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF The extension name of a Java bytecode file is ________. You Answered.java.exe Correct Answer.class.obj  Question 4 1 / 1 pts Every statement in Java ends with ________. a comma (,) an asterisk (*) Correct! a semicolon (;) a period (.)  Question 5 1 / 1 pts ________ translates high-level language program into machine language program. CPU An assembler The operating system Correct! A compiler  Question 6 1 / 1 pts The expression 4 + 20 / (3 - 1) ∗ 2 is evaluated to ________. 25 4 Correct! 24 20 9  Question 7 0 / 1 pts https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 2/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF The expression (int)(76.0252175 ∗ 100) / 100 evaluates to ________. 76.03 Correct Answer 76 You Answered 76.02 76.0252175  Question 8 1 / 1 pts Which of the following are constants, according to Java naming conventions? Correct! COUNT All letters in a constant are in uppercase. In a multiple-word constant, the words are connected using underscores. read ReadInt Test Correct! MAX_VALUE All letters in a constant are in uppercase. In a multiple-word constant, the words are connected using underscores.  Question 9 1 / 1 pts If you attempt to add an int, a byte, a long, and a double, the result will be a(n) ________ value. Correct! double long int byte  Question 10 1 / 1 pts What is the value of (double)5/2? 3 2.0 3.0 https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 3/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF 2 Correct! 2.5  Question 11 1 / 1 pts Analyze the following program fragment: int x; double d = 1.5; switch (d) { case 1.0: x = 1; case 1.5: x = 2; case 2.0: x = 3; } The program has a compile error because the required break statement is missing in the switch statement. The program has a compile error because the required default case is missing in the switch statement. Correct! The switch control variable cannot be double. The switch value cannot be a floating-point number. So the correct answer is C. No errors.  Question 12 1 / 1 pts What is the output of the following code? int x = 0; if (x < 4) { x = x + 1; } System.out.println("x is " + x); x is 2 Correct! x is 1 Since x is 0 before the if statement, x &lt; 4 is true, x becomes 1 after the statement x = x + 1. The correct answer is B. x is 3 x is 0 https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 4/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF x is 4  Question 13 1 / 1 pts What is the possible output from System.out.println((int)(Math.random() * 4))? Correct! 0 Math.random() returns a real value between 0.0 and 1.0, excluding 1.0. Math.random() * 4 yields a real value between 0.0 and 4.0, excluding 4.0. After casting, the resulting integer may be 0, 1, 2, or 3. Correct! 1 Math.random() returns a real value between 0.0 and 1.0, excluding 1.0. Math.random() * 4 yields a real value between 0.0 and 4.0, excluding 4.0. After casting, the resulting integer may be 0, 1, 2, or 3. Correct! 2 Math.random() returns a real value between 0.0 and 1.0, excluding 1.0. Math.random() * 4 yields a real value between 0.0 and 4.0, excluding 4.0. After casting, the resulting integer may be 0, 1, 2, or 3. Correct! 3 Math.random() returns a real value between 0.0 and 1.0, excluding 1.0. Math.random() * 4 yields a real value between 0.0 and 4.0, excluding 4.0. After casting, the resulting integer may be 0, 1, 2, or 3. 4  Question 14 1 / 1 pts The ________ method parses a string s to an int value. Integer.parseInteger(s); Correct! Integer.parseInt(s); The parseInt method is defined in the Integer class. B is correct. integer.parseInt(s); integer.parseInteger(s);  Question 15 1 / 1 pts Suppose i is an int type variable. Which of the following statements displays the character whose Unicode is stored in variable i? System.out.println(i + " "); System.out.println(i); https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 5/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF Correct! System.out.println((char)i); (char)i casts a number into a character. System.out.println((int)i);  Question 16 1 / 1 pts Which of the following is the correct expression of character 4? "4" Correct! '4' You have to write '4'. 4 '\0004'  Question 17 1 / 1 pts Will the following program terminate? int balance = 10; while (true) { if (balance < 9) break; balance = balance - 9; } Correct! Yes Yes. Before the loop, balance is 10. The loop-continuation-condition is always true. In the first iteration, balance is reduced to 1. In the second iteration, the break statement is executed since (balance &lt; 9) is now true. The correct answer for this question is A. No  Question 18 1 / 1 pts Is the following loop correct? for ( ; ; ); Correct! https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 6/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF Yes Yes. This is equivalent to for (; true; ). No  Question 19 1 / 1 pts What is the value of balance after the following code is executed? int balance = 10; while (balance >= 1) { if (balance < 9) break; balance = balance - 9; } 2 0 Correct! 1 Before the loop, balance is 10. The loop-continuation-condition is true (10 &gt;= 1). In the first iteration, balance is reduced to 1. Since 1 &gt;= 1 is true, the loop body is executed. Since balance &lt; 9 is true, the break statement is executed to exit the loop. So, balance is 1 after the loop is finished. The correct answer for this question is C. -1  Question 20 0 / 1 pts Analyze the following code: class Test { public static void main(String[] args) { System.out.println(xmethod(5)); } public static int xmethod(int n, long t) { System.out.println("int"); return n; } https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 7/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF public static long xmethod(long n) { System.out.println("long"); return n; } } The program runs fine but displays things other than 5. Correct Answer The program displays long followed by 5. The program displays int followed by 5. You Answered The program does not compile because the compiler cannot distinguish which xmethod to invoke.  Question 21 1 / 1 pts Which of the following is the best for generating random integer 0 or 1? (int)(Math.random() + 0.2) (int)(Math.random() + 0.8) Correct! (int)(Math.random() + 0.5) (int)Math.random() (int)Math.random() + 1  Question 22 1 / 1 pts A variable defined inside a method is referred to as ________. Correct! a local variable a block variable a method variable a global variable  Question 23 1 / 1 pts Arguments to methods always appear within ________. curly braces brackets Correct! parentheses https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 8/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF quotation marks  Question 24 1 / 1 pts Assume int[] scores = {1, 20, 30, 40, 50}, what is the output of System.out.println(java.util.Arrays.toString(scores))? {1, 20, 30, 40, 50} {1 20 30 40 50} Correct! [1, 20, 30, 40, 50] [1 20 30 40 50]  Question 25 0 / 1 pts Which correctly creates an array of five empty Strings? String[ ] a = new String ; for (int i = 0; i < 5; a[i++] = null); Correct Answer String[] a = {"", "", "", "", ""}; String a; You Answered String[] a = new String ;  Question 26 1 / 1 pts Do the following two programs produce the same result? Program I: public class Test { public static void main(String[] args) { int[] list = {1, 2, 3, 4, 5}; reverse(list); for (int i = 0; i < list.length; i++) System.out.print(list[i] + " "); } public static void reverse(int[] list) { int[] newList = new int[list.length]; for (int i = 0; i < list.length; i++) https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 9/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF newList[i] = list[list.length - 1 - i]; list = newList; } } Program II: public class Test { public static void main(String[] args) { int[] oldList = {1, 2, 3, 4, 5}; reverse(oldList); for (int i = 0; i < oldList.length; i++) System.out.print(oldList[i] + " "); } public static void reverse(int[] list) { int[] newList = new int[list.length]; for (int i = 0; i < list.length; i++) newList[i] = list[list.length - 1 - i]; list = newList; } } Correct! Yes No  Question 27 1 / 1 pts Which of the following statements are valid? int i = new int(30); Correct! double d[] = new double; e would be corrected if it is char[] c = new char[]{'a', 'b', 'c', 'd'}; char[] c = new char(); Correct! int[] i = {3, 4, 3, 2}; e would be corrected if it is char[] c = new char[]{'a', 'b', 'c', 'd'}; https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 10/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF char[] c = new char{'a', 'b', 'c', 'd'};  Question 28 0 / 1 pts 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 prints n is 3. Correct Answer The code has a compile error because xMethod is not declared static. You Answered The code prints n is 2. The code has a compile error because xMethod does not return a value. The code prints n is 1.  Question 29 1 / 1 pts Suppose TestSimpleCircle and SimpleCircle are in two separate files named TestSimpleCircle.java and SimpleCircle.java, respectively. What is the outcome of compiling TestsimpleCircle.java and then SimpleCircle.java? Only TestSimpleCircle.java compiles. Only SimpleCircle.java compiles. Correct! Both compile fine. Neither compiles successfully.  https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 11/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF Question 30 1 / 1 pts Which is the advantage of encapsulation? It changes a class's contract without changing the implementation and causes no consequential changes to other code. Correct! It changes the implementation without changing a class's contract and causes no consequential changes to other code. Only public methods are needed. Making the class final causes no consequential changes to other code.  Question 31 1 / 1 pts What is the output of the following code? String s = "University"; s.replace("i", "ABC"); System.out.println(s); UnABCversABCty Correct! University No method in the String class can change the content of the string. String is an immutable class. UnABCversity UniversABCty  Question 32 1 / 1 pts What is displayed by the following statement? System.out.println("Java is neat".replaceAll("is", "AAA")); JavaAAAneat Correct! Java AAA neat JavaAAA neat Java AAAneat  Question 33 1 / 1 pts https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 12/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF Assume s is "ABCABC", the method ________ returns an array of characters. toChars(s) String.toCharArray() s.toChars() String.toChars() Correct! s.toCharArray()  Question 34 1 / 1 pts Which of the following statements are true? Correct! "class A extends B" means A is a subclass of B. A subclass is a subset of a superclass. "class A extends B" means B is a subclass of A. Correct! A subclass is usually extended to contain more functions and more detailed information than its superclass.  Question 35 1 / 1 pts What modifier should you use on the members of a class so that they are not accessible to another class in a different package, but are accessible to any subclasses in any package? private Correct! protected public Use the default modifier.  Question 36 1 / 1 pts Which of the following is incorrect? Correct! A constructor may be static. A constructor cannot be static, because you use a constructor to create a specific instance. A constructor may be private. In this case, the use cannot create an instance using this constructor. For example, the constructor in the Math class is private. A constructor may invoke a static method just like any method can invoke a static method. A constructor can invoke an overloaded constructor using the this keyword. So, the correct answer is A. https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 13/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF A constructor may invoke an overloaded constructor. A constructor invokes its superclass no-arg constructor by default if a constructor does not invoke an overloaded constructor or its superclass's constructor. A constructor may be private. A constructor may invoke a static method.  Question 37 1 / 1 pts The output from the following code is ________. java.util.ArrayList list = new java.util.ArrayList(); list.add("New York"); java.util.ArrayList list1 = (java.util.ArrayList)(list.clone()); list.add("Atlanta"); list1.add("Dallas"); System.out.println(list1); [New York] [New York, Atlanta] Correct! [New York, Dallas] The code added New York to list and cloned list1 from list. list1 now contains New York. Dallas is added to list1. So list1 contains New Your and Dallas. [New York, Atlanta, Dallas]  Question 38 0 / 1 pts Suppose A is an interface, B is a concrete class with a no-arg constructor that implements A. Which of the following are correct? A a = new A(); Correct! A a = new B(); Since B is a concrete class with a no-arg constructor, answer choice D is correct. Since an instance of B is also an instance of A, answer choice B is also correct. You Answered B b = new A(); Correct Answer B b = new B(); https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 14/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF  Question 39 1 / 1 pts Which of the following statements regarding abstract methods is false? A class that contains abstract methods must be abstract. It is possible to declare an abstract class that contains no abstract methods. An abstract method cannot be contained in a nonabstract class. Abstract classes have constructors. Correct! A data field can be declared abstract. E is wrong, because a data field cannot be declared abstract. Only methods and classes can be declared abstract.  Question 40 1 / 1 pts Assume double[][] x = new double, what are x.length and x.length? Correct! 4 and 5 5 and 4 4 and 4 5 and 5  Question 41 0 / 1 pts What is the output of the following program? public class Test { public static void main(String[] args) { int[][] values = {{3, 4, 5, 1 }, {33, 6, 1, 2}}; for (int row = 0; row < values.length; row++) { java.util.Arrays.sort(values[row]); for (int column = 0; column < values[row].length; column++) System.out.print(values[row][column] + " "); System.out.println(); } } } The program prints two rows 3 4 5 1 followed by 33 6 1 2 https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 15/16 10/16/24, 10:54 PM Practice Quiz for test: JAVA Embedded Applications - CENG-10017-02 - 13595.202435 - FF You Answered The program prints one row 1 3 4 5 1 2 6 33 The program prints on row 3 4 5 1 33 6 1 2 Correct Answer The program prints two rows 1 3 4 5 followed by 1 2 6 33 The program prints two rows 3 4 5 1 followed by 2 1 6 33  Question 42 1 / 1 pts What is the index variable for the element at the first row and first column in array a? a Correct! a a a https://mycanvas.mohawkcollege.ca/courses/108456/quizzes/438944 16/16

Use Quizgecko on...
Browser
Browser