COMP 308 JAVA FOR PROGRAMMERS FINAL ACTUAL EXAMINATION TEST 2026 TIPS POSSIBLE QUESTIONS A, Exams of Object Oriented Programming

COMP 308 JAVA FOR PROGRAMMERS FINAL ACTUAL EXAMINATION TEST 2026 TIPS POSSIBLE QUESTIONS ANSWERS GRADED A+

Typology: Exams

2025/2026

Available from 01/31/2026

HighMark_Prep
HighMark_Prep 🇺🇸

5

(3)

27K documents

1 / 27

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COMP 308 JAVA FOR PROGRAMMERS
FINAL ACTUAL EXAMINATION TEST 2026
TIPS POSSIBLE QUESTIONS ANSWERS
GRADED A+
int n1 = 12;
int n2 = 5;
int n3 = ++n1 - n1--;
What is the result of the code above? Answer: n3 = 8 and n2 = 4 and n1
= 13
Identify the statements that correctly increase the variable amount by
2. Select ALL that apply. Answer: Amount += 2;
Amount = amount + 2;
Identify the components of object-oriented programming in Java.
Select ALL that apply. Answer: Encapsulation
Inheritance
Abstraction
Polymorphism
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download COMP 308 JAVA FOR PROGRAMMERS FINAL ACTUAL EXAMINATION TEST 2026 TIPS POSSIBLE QUESTIONS A and more Exams Object Oriented Programming in PDF only on Docsity!

COMP 308 JAVA FOR PROGRAMMERS

FINAL ACTUAL EXAMINATION TEST 2026

TIPS POSSIBLE QUESTIONS ANSWERS

GRADED A+

⩥ int n1 = 12; int n2 = 5; int n3 = ++n1 - n1--; What is the result of the code above? Answer: n3 = 8 and n2 = 4 and n = 13 ⩥ Identify the statements that correctly increase the variable amount by

  1. Select ALL that apply. Answer: Amount += 2; Amount = amount + 2; ⩥ Identify the components of object-oriented programming in Java. Select ALL that apply. Answer: Encapsulation Inheritance Abstraction Polymorphism

⩥ Identify the "blueprint" from which individual Java objects are created. Answer: Class ⩥ This contains the JVM and Java Class Library. Answer: JRE ⩥ Simple data types for storing integers, real numbers, characters and Booleans are called ____?____ in Java. Answer: primitives ⩥ int result = 3 / 10; What is the result of the code above? Answer: 0 is stored in result ⩥ long loan = 1234; int number = loan; The code above does not compile. How could the code be corrected? Select ALL that apply. Answer: Add a cast to long Add a cast to int ⩥ Identify the correct Java variable assignment statements. Select ALL that apply. Answer: int bin = 0b111; double cost = 2_345.5_; double num - 1_00_0.0_0;

d. A compiled Java filename has a .class extension. ⩥ A device needs a ____ to run a Java program Answer: JVM ⩥ Identify the true statements about Java. Select ALL that apply. Answer: a. Java is case-sensitive b. A java program must have at least one class c. Java programs execute from the main method d. The name of a public Java Class must match its filename e. Java class names should begin with an upper case alphabet character ⩥ What term is used to describe compiled Java code? Answer: Bytecode ⩥ Source code file Hello.java has been compiled. Which one of these will execute it? Answer: java Hello ⩥ Where are Java used programs used? Select ALL that apply. Answer: a. In some mobile devices b. On web servers c. In some modern motor vehicles d. In some kitchen appliances

⩥ Identify the legal Java identifiers. Select ALL that apply. Answer: a. CanOfWorms b. _firstname c. $price ⩥ Which one will compile a Java source code file named Test.java? Answer: javac Test.java ⩥ Identify the popular features of Java. Select ALL that apply. Answer: a. Java is object-oriented. b. Java can be embedded in Web pages. c. Java is platform independent ⩥ Identify the data type(s) that can be used in a Java switch expression. Select ALL that apply. Answer: a. String b. Short c. Int d. Char ⩥ 1. Identify the relational operators. Select ALL that apply. Answer: a. <= b. == c. >

System.out.print(++var2); What is printed by the code above? Answer: 2 ⩥ int x = 3; int y = 5; int z = x++ > --y? x : y; System.out.print(z); What (if anything) is printed? Answer: 4 ⩥ int x, y = 1; x = 10; if(x != 10 && x / 0 == 0) System.out.println(y); Else System.out.println(++y); What is the output of the code above? Answer: 2 ⩥ Boolean odd = 12 % 2 == 1; If (odd = false) System.out.println("odd"); Else System.out.println("Even");

What is printed (if anything) by the code above? Answer: Even ⩥ Which of these operators might not have to evaluate the right hand operand? Answer: || ⩥ Identify the true statements about Java strings. Select ALL that apply. Answer: a. String is a reference type. b. Java strings are mutable. c. String is a class. d. A String object can be instantiated without using new. e. Strings once made cannot be made larger or smaller ⩥ What is the result of this statement? System.out.println(1 + 2 + "b"); Answer: 3b ⩥ String a = "4"; A+="5"; A+=6; System.out.print(a); Answer: 456 ⩥ String s1 = "Hello world"; String s2 = s1; Answer: a. The s2 variable holds the string "Hello world".

⩥ 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 ⩥ For (int n = 0; n <= 12; n++) { System.out.print(n + ""); } System.out.println(n); What is the output of line 7? Answer: Nothing. Compilation fails ⩥ For(int I = 0; i < 6; i++) { For(int j = 1; j <= 5; j++) { System.out.print(I + j + " "); } System.out.println(); }

What is printed by the third iteration of the outer loop? Answer: 3 4 5 6 7 ⩥ int x=1; while(x <=5) { x++; System.out.print(x); } 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)

⩥ 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;

  1. area(length, width); As used in line 7, length and width are called the ? of the area method? Answer: Arguments ⩥ 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 ++ ) {

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<>();

  1. counts.add(10);
  2. counts.add(new Integer(8)); Identify the true statement regarding the code above. 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.

? 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 {

  1. public Person() {

  2. } 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 ⩥ What is called by the throw statement? Answer: A catch block. ⩥ Identify the true statements. Select ALL that apply. Answer: a. Class Throwable is the parent class for all exceptions.