1 / 42

COMP248 Tutorial 12

COMP248 Tutorial 12. Review and Exam Preparation. Question 1: Forgetting a semicolon at the end of a programming statement is a: a) Run-time error b) Compile-time error c) Logical error. Question 1: Forgetting a semicolon at the end of a programming statement is a: a) Run-time error

ward
Download Presentation

COMP248 Tutorial 12

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMP248 Tutorial 12 Review and Exam Preparation

  2. Question 1: Forgetting a semicolon at the end of a programming statement is a: • a) Run-time error • b) Compile-time error • c) Logical error

  3. Question 1: Forgetting a semicolon at the end of a programming statement is a: • a) Run-time error • b) Compile-time error • c) Logical error

  4. Question 2: Producing inaccurate results is a: • a) Logical error • b) Compile-time error • c) Run-time error

  5. Question 2: Producing inaccurate results is a: • a) Logical error • b) Compile-time error • c) Run-time error

  6. Question 3 What is the Java expression for 4a2 + 2b * c? • a) (4 * a) + (2 * b) * c • b) ((4 * a * a) + (2 * b)) * c • c) (4 + a * a) + ((2 + b) * c) • d) (4 * a * a) + ((2 * b) * c)

  7. Question 3 What is the Java expression for 4a2 + 2b * c? • a) (4 * a) + (2 * b) * c • b) ((4 * a * a) + (2 * b)) * c • c) (4 + a * a) + ((2 + b) * c) • d) (4 * a * a) + ((2 * b) * c)

  8. Question 4 The syntax that declares 2 Java variables called x and y of type integer is: • a) integer x; y; • b) int x, y; • c) integer x, y; • d) int x;y;

  9. Question 4 The syntax that declares 2 Java variables called x and y of type integer is: • a) integer x; y; • b) int x, y; • c) integer x, y; • d) int x;y;

  10. Question 5: What is the result of the expression: "abc" + 4 + 5 + "fgh"? • a) "abc4fgh5" • b) "abc9fgh" • c) "abc45fgh" • d) Not a legal Java expression

  11. Question 5: What is the result of the expression: "abc" + 4 + 5 + "fgh"? • a) "abc4fgh5" • b) "abc9fgh" • c) "abc45fgh" • d) Not a legal Java expression

  12. Question 6: What is the output of the following instruction? • System.out.println("The value of 25/4 is " + 25/4); • a) The value of 25/4 is 6 • b) The value of 6 is 6 • c) The value of 6.25 is 6.25 • d) The value of 25/4 is 6.25

  13. Question 6: What is the output of the following instruction? • System.out.println("The value of 25/4 is " + 25/4); • a) The value of 25/4 is 6 • b) The value of 6 is 6 • c) The value of 6.25 is 6.25 • d) The value of 25/4 is 6.25

  14. Question 7: Assume the following declarations: • int num1 = 25, num2 = 50; • double fResult; • What will be the value of fResult after the execution of: fResult = (double) num1 / • num2; • a) 0.0 • b) 1.0 • c) 4.0 • d) 0.5

  15. Question 7: Assume the following declarations: • int num1 = 25, num2 = 50; • double fResult; • What will be the value of fResult after the execution of: fResult = (double) num1 / • num2; • a) 0.0 • b) 1.0 • c) 4.0 • d) 0.5

  16. Question 8 What will be the value of a after the following instructions? • int a = 6, b = -6, c= 0; • a = 5 + (b++) + (++c); • a) 6 • b) 2 • c) 0 • d) 4

  17. Question 8 What will be the value of a after the following instructions? • int a = 6, b = -6, c= 0; • a = 5 + (b++) + (++c); • a) 6 • b) 2 • c) 0 • d) 4

  18. Question 9: What is the value of (true && (5>6)) • a) false • b) it cannot be determined • c) true

  19. Question 9: What is the value of (true && (5>6)) • a) false • b) it cannot be determined • c) true

  20. Question 10: Assume the following declarations: • int a = 3; • int b = 5; • When evaluating the expression: ( a < b || b < 10 ) will the operand (b < 10) be • evaluated? • a) yes • b) no • c) it depends where the expression is placed

  21. Question 10: Assume the following declarations: • int a = 3; • int b = 5; • When evaluating the expression: ( a < b || b < 10 ) will the operand (b < 10) be • evaluated? • a) yes • b) no • c) it depends where the expression is placed

  22. Question 11: Consider the loop: • for (int x = 1; x < 5; increment) • System.out.print(x + 1); • If the last value printed is 5, which increment was used? • a) x++ • b) x+=1 • c) Any of the other answers would work • d) ++x

  23. Question 11: Consider the loop: • for (int x = 1; x < 5; increment) • System.out.print(x + 1); • If the last value printed is 5, which increment was used? • a) x++ • b) x+=1 • c) Any of the other answers would work • d) ++x

  24. Question 12: What does this fragment print? • int result = 9; • for (int cnt = 2; cnt < result; cnt += 3) • result = cnt; • System.out.println("result = " + result); • a) result = 2 • b) result = 8 • c) result = 9 • d) result = 11

  25. Question 12: What does this fragment print? • int result = 9; • for (int cnt = 2; cnt < result; cnt += 3) • result = cnt; • System.out.println("result = " + result); • a) result = 2 • b) result = 8 • c) result = 9 • d) result = 11

  26. Question 13: In order to distinguish among overloaded methods, the compiler uses the • method's signature. A signature is composed of: • a) A method's name, and its return type. • b) A method's name, its return type, and the number of parameters. • c) A method's name, and the number, order and types of its parameters. • d) A method's name, its return type, and the number, order, and types of its parameters

  27. Question 13: In order to distinguish among overloaded methods, the compiler uses the • method's signature. A signature is composed of: • a) A method's name, and its return type. • b) A method's name, its return type, and the number of parameters. • c) A method's name, and the number, order and types of its parameters. • d) A method's name, its return type, and the number, order, and types of its parameters

  28. Question 14: A method named computeSum() is located in class Payroll. To call the • method from within class Payroll, we can use the statement: • a) computeSum(Payroll); • b) computeSum(); • c) Payroll.computeSum(); • d) main.computeSum();

  29. Question 14: A method named computeSum() is located in class Payroll. To call the • method from within class Payroll, we can use the statement: • a) computeSum(Payroll); • b) computeSum(); • c) Payroll.computeSum(); • d) main.computeSum();

  30. Question 15 Assume we have a method defined this way: public int aMethod(boolean b) • {…} • What can be placed inside the body of the method? • a) return 5; • b) return true; • c) return 5==5; • d) return;

  31. Question 15 Assume we have a method defined this way: public int aMethod(boolean b) • {…} • What can be placed inside the body of the method? • a) return 5; • b) return true; • c) return 5==5; • d) return;

  32. Question 16 Assume we have a method defined this way: public boolean aMethod(int n) • {…} • Which of the following contexts is a correct way of calling this method: • a) while (aMethod()) {…} • b) int x = aMethod(5); • c) System.out.print(aMethod(true)); • d) if (aMethod(5)) {…}

  33. Question 16 Assume we have a method defined this way: public boolean aMethod(int n) • {…} • Which of the following contexts is a correct way of calling this method: • a) while (aMethod()) {…} • b) int x = aMethod(5); • c) System.out.print(aMethod(true)); • d) if (aMethod(5)) {…}

  34. Question 17: Most, but not all, of the wrapper classes are spelled the same as the • keyword for the data type that they "wrap," but with an initial capital letter. Which • wrappers don't follow this rule? • a) Integer, Short, Byte. • b) Character, String. • c) Integer, Character. • d) Float, Double.

  35. Question 17: Most, but not all, of the wrapper classes are spelled the same as the • keyword for the data type that they "wrap," but with an initial capital letter. Which • wrappers don't follow this rule? • a) Integer, Short, Byte. • b) Character, String. • c) Integer, Character. • d) Float, Double.

  36. Question 18: An Airplane class is to be defined. This class will represent an airplane • within an application for an airline company. The Airplane class will provide storage for • the number of planes operated by the airline. The number of planes operated by the • airline will be declared as • a) an instance variable • b) a class variable (static) • c) a class method (static) • d) an instance method

  37. Question 18: An Airplane class is to be defined. This class will represent an airplane • within an application for an airline company. The Airplane class will provide storage for • the number of planes operated by the airline. The number of planes operated by the • airline will be declared as • a) an instance variable • b) a class variable (static) • c) a class method (static) • d) an instance method

  38. Question 19: Assume that we have a class Animal to represent animals in a zoo. • - The class Animal has a constructor that takes 2 arguments: a string and an integer • - The class Animal has no equals method. • In the driver, if we declare 2 objects like this: • Animal zozo = new Animal("tiger", 5); • Animal titi = new Animal ("tiger", 5); • What is the value of the expression (zozo == titi). • a) true • b) false • c) it depends on the definition of == for that class • d) it is a syntax error, because the class does not have an equals method

  39. Question 19: Assume that we have a class Animal to represent animals in a zoo. • - The class Animal has a constructor that takes 2 arguments: a string and an integer • - The class Animal has no equals method. • In the driver, if we declare 2 objects like this: • Animal zozo = new Animal("tiger", 5); • Animal titi = new Animal ("tiger", 5); • What is the value of the expression (zozo == titi). • a) true • b) false • c) it depends on the definition of == for that class • d) it is a syntax error, because the class does not have an equals method

  40. Question 20: Which of the following statements is true: • (a) In Java, you can invoke (call) a nonstatic (ordinary) method from within a • static method. • (b) You can use the this reference in a static method. • (c) You can use a static variable in a nonstatic (ordinary) method. • (d) All the methods in the Math class are nonstatic (ordinary) methods.

  41. Question 20: Which of the following statements is true: • (a) In Java, you can invoke (call) a nonstatic (ordinary) method from within a • static method. • (b) You can use the this reference in a static method. • (c) You can use a static variable in a nonstatic (ordinary) method. • (d) All the methods in the Math class are nonstatic (ordinary) methods.

  42. GOOD LUCK ON EXAMS!

More Related