















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
JAVA PROGRAMMING TENTH EDITION EXAM PREP 2026 QUESTION BANK AND ANSWER KEY MASTER CODING SKILLS SET
Typology: Exams
1 / 23
This page cannot be seen from the preview
Don't miss anything!
















โ String s1 = "Hello world"; String s2 = s1; Answer: a. The s2 variable holds the string "Hello world". a. The s2 variable holds a reference to the string "Hello world". โ Identify the method that returns the number of characters in a string. Answer: Length() โ Match the format specifiers with the data. Answer: a. %d - integer b. %e - scientific notation c. %f - floating point d. %c - character e. %b - Boolean f. %s - string
โ Identify the true statements regarding Java loops. Select ALL that apply. Answer: a. A while loop might not run at all. b. A do-while loop always runs at least once. c. Loops can be nested in other loops to any depth as desired. โ A while loop is a ? loop. Answer: Pretest โ In which instance can a loop not require braces? Answer: When only one statement is to be repeated โ The Java continue statement causes execution to skip to Answer: The next iteration in the loop โ Int n; For(n=8; n < 30; n += 5) { // } System.out.print(n); What is printed when the loop above has finished? Answer: 33
What is the output of the code above? Answer: 2 3 4 5 6 โ int z = 2. sum = 0; while (z < 9) { z++; sum = sum + z; } System.out.print(sum); What is the output of the code above? Answer: 42 โ int b =0, sum =0; while (b < 6) { ++b; if(b % 2 == 0) continue; b++; sum = sum + b; } System.out.print(sum); When the above program is run, the output would be 13?
Answer: False โ 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
โ To be capable of being called in the main method of a Java program, a method defined in the same class must have the ? modifier? Answer: Static โ public static void main(String[] args) { int number = 10; doubleNum(number); System.out.println(number); } public static void doubleNum(int n) { System.out.println(n * 2); } For the program above what will be the value displayed to the system console in the highlighted text? Answer: 10 โ public static void main(String[] args) { ArrayList langs = new ArrayList(); lands.add("Java"); lands.add("C++"); lands.add("Python");
lands.add("2,null"); lands.add("2,null"); lands.add("4, "PHP"); for(int i = 0, i < langs.size(); i ++ ) { System.out.print(langs.get(i) + " "); } } 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.
Answer: No errors, code compiles okay. โ Identify the true statements. Select ALL that apply. Answer: a. Constructors are called with the new operator. b. Constructors can be overloaded. c. Constructors must have the same name as the class. โ Identify the true statements. Select ALL that apply. Answer: a. A static method cannot access the data members of its own class. b. Static methods are also called class methods. c. Static methods of a class can be called without instantiating the class. โ Identify the true statements. Select ALL that apply. Answer: a. Anonymous objects are possible in Java. b. Constants in a class should be declared as final static. c. Static variable and static methods of a class can be accessed by an object of that class and by the class name. โ public class Person { private String name;
What term(s) describe(s) name in the snippet above? Select ALL that apply. Answer: a. Instance variable b. Field c. Data member d. Attribute โ What does the public visibility modifier mean? Answer: Means accessible from any other classes. โ Identify the true statements. Select ALL that apply. Answer: a. A getter method has the same return-type as the field it retrieves and takes no parameters. b. A setter method is a return-type void and takes a parameter of the same type as its field. c. Setters and getters are not required for public instance variables. โ public class Person { private char gender; static int number; // ...
โ 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 {
public Person() {
} What type of constructor is illustrated by lines 5 through 7? Answer: No-arg โ Data fields are encapsulated with which modifier? Answer: Private โ What Java keyword sometimes used in a class definition refers to the class itself? Answer: This โ String str2 = "b$h&".replaceAll("@&$","oo"); System.out.println(str2.replaceAll("[@&$]","oo")); What is printed? Answer: boohoo โ StringBuilder sb = new StringBuilder(); sb.append("Hey Java"); System.out.println(sb.capacity() - sb.length()); Answer: 8
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) { while (n > 0) { System.out.print(message); n--; } } What is k after invoking nPrint("A message", k)? int k = 2; nPrint("A message", k);
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