Description

DTT204Programming In Java Multiple Choice Questions Name: ______________________________________________ Student ID: _______________________________________ 1. What will be displayed on the screen by the following code segment? String word = “Hello”; System.out.println(word); (a) word (b) Hello (c) “Hello” (d) “Hello”; 2. In the previous question, println is the name of a (a) variable (b) method (c) class (d) object 3. What will be output by the following Java statement? System.out.println((double)(12/5)); (a) 2.4 (b) 2.0 (c) 2 (d) 2.5 4. What will be output by the following Java statement? System.out.println((double)12/5); (a) 2.4 (b) 2.0 (c) 2 (d) 2.5 5. What will be output by the following Java statement? System.out.println((int)(12.0/5)); (a) 2.4 (b) 2.0 (c) 2 (d) 2.5 6. What will be output by the following Java statement? System.out.println((int)12.0/5)); (a) 2.4 (b) 2.0 (c) 2 (d) 2.5 1 The value of the expression 5 * x – n / 5 is (a) 12.7 (d) 11.7. Suppose we have defined int num1 = 50. num2 = 50. The value of the expression (num1 == num2) is (a) true (b) false (c) 50 (d) 0 10. public class Midterm { public static void main (String [] args) { final int SIZE = 10. n = 4. } } The identifier Midterm in the above code is the name of (a) a method (b) an object (c) a class (d) a file 11. The identifier SIZE in the above code is a (a) reference variable (b) constant (c) name of a method (d) none of the above 2 .drawSquare(SIZE). World w1 = new World(). The identifier num in the above code is a (a) reference variable (b) variable of int type (c) constant (d) name of a method 12. The value of the expression m / n + m % n is (a) 6.5 (b) 11.7 (c) 1. Suppose we have defined int m = 18.forward(num).5 (b) 6 (c) 6.5. t1. int num = 75.5 9. Suppose we have defined int n = 4. Turtle t1 = new Turtle(w1).0 (d) 100 8. t1. double x = 2. k <= 11. 3 . What value is stored in intArr[1] ? (a) 1 (b) 2 (c) 4 (d) 0 15. Which of the following for loops would do this correctly? (a) for (int k = 1.10}. and (c) 14. (b) for (int k = 0. (c) for (int k = 1. (b). k++) intArr2[k] = 100.13.length – 1] (d) intArr[0] 16.4.8. k++) intArr2[k] = 100. (d) for (int k = 0. k++) intArr2[k] = 100. k <= 12. Which of the following in the above code is/are object methods? (a) World (b) Turtle (c) forward (d) all of (a). Suppose we want to store the value 100 in each of the elements of the array intArr2 declared by: int [] intArr2 = new int[12].6. k++) intArr2[k] = 100. k <= 12. Suppose we have an array declared by int [] intArr = {2.length] (c) intArr[intArr. k <= 11. How can we refer to the last element in the array of the previous question? (a) intArr[10] (b) intArr[intArr. World w1 = new World().34. How many variables are declared in this code segment? (a) 5 (b) 6 (c) 7 (d) none of the above 18. } System. String test. int count = 5. How many objects are created in this code segment? (a) 0 (b) 1 (c) 2 (d) 3 19.out. while (count >1) { sum = sum + count. 17. n2 = 0. What will be output by the following code segment? int sum = 0. count = count + 2. Turtle t2 = t1. double x = 12. What will be output by the following code segment? int sum = 0. (a) True (b) False 20. The variables t1 and t2 in the above code segment refer to different objects of the Turtle class.out. (a) 10 (b) 15 (c) 4 (d) 9 21. count = count + 2. } System. int count = 1. while (count < 5) { sum = sum + count. (a) 10 (b) 15 (c) 4 (d) 9 4 . int n1. Turtle t1 = new Turtle(w1).println(sum).println(sum). none of the above 23. } a. row <= 3. * * * e.println().out. } System. row ++) { for (int count = 1. *** *** *** d. count <= (4 – row).22.print(“*”). Which of these keyword must be used to inherit a class? a) super b) this c) extent d) extends 24.out. * ** *** b. *** ** * c. count ++) { System. What will be output by the following code segment? for (int row = 1. Which of these keywords is used to refer to member of super class from a sub class? a) upper b) super c) this d) None of the mentioned 5 . statement 6 . Comment D. javac First. javac First C. Variable C. System. Demo. To compile a program named First. Declares array1 to be a reference to an array of double values B. Demo. use the following command: A. of superclass A by subclass B? a) super(void). Demo. c) super.byte 29. What does the following statement do? double[] array1 = new double[10].9 D. Class definition B. Which one of the following would contain the translated Java byte code for a program named Demo? A. Which of these is correct way of calling a constructor having no parameters.class D. Which of these is correct way of inheriting class A by class B? a) class B + class A {} b) class B inherits class A {} c) class B extends A {} d) class B extends class A {} 26. Demo.println().25. A.A().java D. java First.().javac 30. b) superclass.out.code C. All of the above 28. Creates an instance of an array of 10 double values C. compile First.java B. Will allow valid subscripts in the range of 0 . d) super().A Java program must have at least one of these: A. 27.java B. standard output device B.Which of the following is NOT a valid comment statement? A. ________ must be declared before they can be used. . 3 D.What is the result of the following expression? 25 / 4 + 4 * 10 % 3 A. you may use the letters a-z. -5 B. secondary storage device D. # 32. A-Z. comments 34. a dollar sign. the beginning of a comment is marked with: A. The first character must be one of the letters a-z.In Java. // B. variables B. */ comment 3 /* D. literals C. 35. /** comment 4 */ 7 . Uppercase and lowercase characters are distinct. Identifiers can contain spaces. or digits 0-9. // comment 1 B. /* comment 2 */ C.The term ________ typically refers to the device that displays console output. 5.In Java.Which of the following is NOT a rule that must be followed when naming identifiers? A. After the first character. key words D. 25 D.25 C.31. liquid crystal display 33. A. and underscore or a dollar sign. A. D. "" C. the underscore.What is the result of the following expression? 10 + 5 * 3 – 20 A. A-Z. central processing unit C. -50 36. C. B. 5 C. 7 37. D. 19 B. A subclass is also called as A. super B. C.Which of these keywords can be used to prevent inheritance of a class? A. B. Final 42. (str1. A method with a return type D. break a problem down into small manageable pieces C. nested class C. derived class D. final static float MAX_LENGTH = 99. The main method C. final static MAX_LENGTH = 99. Do not include the data type in the method call. To declare a constant MAX_LENGTH as a member of the class. A method with the void return type 43. 44. ________ is invoked to create an object. emphasize certain parts of the logic D. 41.98. D. Class D.compareToIgnoreCase(str2) == 0) C. Only A D.38. you write A. speed up the compilation of a program B. constant C. displayValue will not accept a parameter. final double MAX_LENGTH = 99. inner class B. D.Methods are commonly used to: A. There is nothing wrong with the statement.98.98. A and B 39. str1 and str2? A. A. document the program 40. B. (str1. A.equalsIgnoreCase(str2)) B. hidden class 8 . final static double MAX_LENGTH = 99. A constructor B.To do a case insensitive compare which of the following could be used to test the equality of two strings.98. x should be a String. C.What is wrong with the following method call? displayValue (double x). int B. All of the mentioned 9 . try B.45. DecimalFormat() method is available in which package? A. java. double D. Error B. RuntimeExecption D. catch 49. Compilation Time C. Exception C. String 47. All of the mentioned 50.lang B.io 46. Which of these class is related to all the exceptions that can be caught by using catch? A.util C. Which of these class is related to all the exceptions that cannot be caught? A.text D.println("Hello"). Which is acceptable data type for x? switch(x) { default: System. float C. RuntimeExecption D. } A.out. In java. java. Error B. Run Time B. When does Exceptions in Java arises in code sequence? A. None of the mentioned 48. finally C. thrown D. java. Exception C. java. Which of these keywords is not a part of exception handling? A. Can Occur Any Time D. println(2). 6 }} 7 8 class Y extends X 9 { 10 static void staticMethod() 11 { 12 System.51. 21 } 10 . 7 }} 8 9 class B extends A 10 { 11 { 12 System.staticMethod().println(3). 19 }} 20 21 public class MainClass 22 { 23 public static void main(String[] args) 24 { 25 C c = new C().println("Class X"). 13 }} 14 15 class C extends B 16 { 17 { 18 System. 13 }} 14 15 public class MainClass 16 { 17 public static void main(String[] args) 18 { 19 Y test=new Y(). 20 test.out.println("Class Y").out.out. 26 }} 27 52) What will be the output of the following program? ? 1 class X 2 { 3 static void staticMethod() 4 { 5 System.out. What will be the output of the below program? 1 2 3 class A 4 { 5 { 6 System.out.println(1). System. Calculate() method should calculate and display the distance. break. the Alligator"). x += 32.out. y = " + y).print("Buffy. System. default: x *= 3. y = 20. System. Write a method called Calculate that receives two parameters km per litre and tank Size. If the following Java statements are executed.print("Jody. 11 . 54. System.out.out.println("x = " + x + ". switch (x) { case 10: x += 15.out. the Giant\n").println("Adelle. What will be displayed as a result of executing the following code? int x = 5. y /= 4. } 53.} 56. what will be displayed? System. What would be the value of x after the following statements were executed? int x = 10. the Barbarian").println("The top three winners are\n"). Reference : Distance = KM Per Litre / Tank Size. case 12: x -= 5. 55.out. d) Insert a student by the name “Siti“ at index 3 of the ArrayList. print “Found”. Write the code segments for the following questions using ArrayList Student. e) Write the code to print the ArrayList. if (sales < 5000) bonus = 200. print “Not Found”. else if (sales < 10000) bonus = 750. What will be the value of bonus after the following code is executed? int bonus. else bonus = 1250. if none. 12 . c) Delete the name “Ali Ahmad” from the ArrayList. else if (sales < 20000) bonus = 1000.57. sales = 10000. else if (sales < 7500) bonus = 500. 58. b) Delete the name which is the first name in the ArrayList. a) Write the code to check if there is a name called “Siti” in the ArrayList? If there is.
Copyright © 2024 DOKUMEN.SITE Inc.