430 likes | 610 Views
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
E N D
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 • b) Compile-time error • c) Logical error
Question 2: Producing inaccurate results is a: • a) Logical error • b) Compile-time error • c) Run-time error
Question 2: Producing inaccurate results is a: • a) Logical error • b) Compile-time error • c) Run-time error
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)
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)
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;
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;
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
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
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
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
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
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
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
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
Question 9: What is the value of (true && (5>6)) • a) false • b) it cannot be determined • c) true
Question 9: What is the value of (true && (5>6)) • a) false • b) it cannot be determined • c) true
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
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
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
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
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
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
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
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
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();
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();
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;
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;
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)) {…}
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)) {…}
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.
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.
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
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
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
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
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.
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.