









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
COMP 308 JAVA FOR PROGRAMMERS FINAL PAPER 2026 TIPS POSSIBLE QUESTIONS COMPLETE CORRECT ANSWERS ATHABASCA
Typology: Exams
1 / 16
This page cannot be seen from the preview
Don't miss anything!










⩥ The methods of the Math class are ? methods? Answer: Static ⩥ A void method does not contain a return statement, but it is possible. Answer: True ⩥ Identify the true statements about overloaded methods. Select ALL that apply. Answer: a. They must have different modifiers. b. They can have different parameter types. c. They must have the same method name. d. They can have a different number of parameters. ⩥ What term describes a variable that is declared inside a method? Answer: Local variable ⩥ A method can return only on value. Answer: True ⩥ public static void main(String[] args) {
System.out.print("W"; p(); System.out.print("Z"); } public static void p() { System.out.print("X"); System.out.print("Y"); } What is the output of the code above? Answer: WXYZ ⩥ Public static double area(double radius){ ... In the method header above, radius is called a ? Answer: Formal parameter ⩥ 6. int length = 5, width = 8;
What is the output? Answer: Java C++ null null PHP Python ⩥ Identify the data types that can be stored in a Java ArrayList. Select ALL that apply. Answer: a. Integer b. Double c. String ⩥ Identify the true statements. Select ALL that apply. Answer: a. Elements can be appended to an existing ArrayList instance. b. Arrays can store primitive types and reference types. c. Arraylists cannot store primitive data types. ⩥ Select the statement that is false. Answer: An array can be reset by clearing all elements. ⩥ Identify the statement(s) that are true about arrays. Select ALL that apply. Answer: a. The default value for the elements in an array of ints is zero. b. An array variable is a reference type. c. The default value for each element in an array of objects is null. d. Once created, an array cannot be re-sized.
⩥ Identify the statements that will NOT compile. Select ALL that apply. Answer: a. ArrayList[String] stock = new ArrayListString; b. ArrayList charas = new ArrayList(); c. Int[4] items = {5,9,11,8} ⩥ 6. ArrayList counts = new ArrayList<>();
⩥ public class Person { private char gender; static int number; // ... public static void main(String[] args) { Person person // ... } public static void callPerson(int hours) { double payRate = 24.99; } } The code above compiles okay. Refer to it to complete this matching exercise. Answer: a. Person: 1 b. Hours: 5 c. Gender: 5 d. payRate: 5 e. number: 2 ⩥ The separation of how a class works internally from its usage is ? Answer: Class abstraction
⩥ ? is a binary relationship between two different classes. Answer: Association ⩥ An aggregating object exclusively own another object. This is ? Answer: Composition ⩥ Identify the statement(s) that compile without error(s). Select ALL that apply. Answer: a. Integer num = 10; b. Integer num = new Integer(10); c. Integer num = new Integer("10"); ⩥ Which of the following correctly assign the string hello to a String? Answer: a. StringBuilder = str = new StringBuiler("hello"); String stt = str.toString(); b. String st = new String("hello"); c. String st = "hello"; d. char[] hello = {'h','e','l','l','o'}; String st = new String(hello); ⩥ 3. public class Person {
b. You can create your own exception classes by extending class Exception. ⩥ Java forces you to deal with ? exceptions. Answer: Checked ⩥ Coding a catch block for a parent exception type before the catch block of one of its subclasses causes a compilation error. Answer: True ⩥ Identify the true statements. Select ALL that apply. Answer: a. The keyword to throw an exception is throw, and the keyword to declare an exception is throws. b. The throws keyword indicates which exception(s) a method might throw. c. Every Java method must indicate the type(s) of exceptions that it might throw. d. One method might throw more than one type of exception. ⩥ Identify the true statements. Select ALL that apply. Answer: a. If errors that might occur can be handled with if blocks, exceptions should not be used. b. One finally block can follow the catch block(s). c. Code in a finally block is always executed. d. Exceptions in the Java API have constructors that can take a string argument that describes the error.
⩥ Select all the valid examples of a runtime exception messages. Answer: a. ArithmeticException b. NullPointerException c. IndexOutOfBoundsException ⩥ The JDK command to compile the file Test.java is ______. Answer: javac Test.java ⩥ Identify the valid statement(s). Select ALL that apply. Answer: Char[] ch=new char[26]; b. double prices[] = {12.95,3.79,14.99,7.49}; ⩥ To obtain the current second, use ______. Answer: System.currentTimeMillis() / 1000 % 60 ⩥ Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative? Answer: ((x < 100) && (x > 1)) || (x < 0) ⩥ What is returned by "AbE".compareToIgnoreCase("abC")? Answer: A positive integer ⩥ Given the following method static void nPrint(String mmessage, int n) {
⩥ RunTimeException and its subclasses are unchecked exceptions. Answer: True ⩥ If no exception occurs in a try-catch block, the code in the finally clause ______. Answer: Is executed ⩥ Int x = 5; Which statement(s) will make x equal to 6? Select ALL that apply. Answer: a. ++x; b. x = ++x; c. x = x + 1; ⩥ To run the compiled file Prog.class from the command line, enter ______. Answer: Java Prog ⩥ Which of the following are legal Java variable names? Select ALL that apply. Answer: a. _name b. value c. $alary ⩥ Identify the statement that will generate a compile error. Answer: Float price = 4.99;
⩥ int = 2; int y =5; int z = x-- + (++y); What is the value of z after the statements above? Answer: 8 ⩥ int num = 3; if (num >= 0) if (num == 0) System.out.print("first string"); else System.out.print("second string "); System.out.print("third string "); What is the output by the code above? Answer: Second string third string ⩥ Which expression returns false if num equals 5? Answer: Num <= 5 ^ num % 2 == 1 ⩥ double price = 14.95; System.out.printf("string",price); Which value for string will output three spaces followed by 14.95? Answer: %8.2f
⩥ When an object is passed to a method, the method receives a reference to the object. Answer: True ⩥ Coding a method in a subclass with the same signature and return type as a method in its superclass is called _______. Answer: overriding ⩥ int num1 = 17, num2 = 5; System.out.print(num1 / num2); What is printed? Enter the output. Answer: 3 ⩥ Scanner input = new Scanner(System.in); System.out.print("Enter your name "); String name = input.next(); System.out.println(name); If the user enters James gosling when the code above runs, what is printed? Answer: James ⩥ An ArrayList class is used to store a mutable group of objects. Answer: True ⩥