You are on page 1of 5

Mike Danielle Adaure

PROG3112 Programming (Java) NCIII Part 2


WEEK 10: FIRST QUARTER EXAM
What is the size in bits of an int?
Answer: 32
Which of the following does not contain a syntax error?
Answer: System.out.println(Hello world!); (POSSIBLE)
= System.out.println("Hello world!"); (INCORRECT)
Which of the following is not a Java primitive type?
Answer: real
Which command compiles the Java source code file Welcome.java?
Answer: javac Welcome.java
Portions of statements that contain calculations are called
Answer: expressions. (POSSIBLE) variables. (INCORRECT)

Java is considered a strongly typed language because:


Answer: Java requires all variables to have a type before they can be used in a program.A (POSSIBLE)
= All of the above. (INCORRECT)
= The primitive types in Java are portable across all computer platforms that support Java.
(INCORRECT)
________ is a graphical language that allows people who design software systems to use an industry
standard notation to represent them.
Answer: The Unified Modeling Language
Which of the following will count down from 10 to 1 correctly?
Answer: for (int j = 10; j >= 1; j--)
The command ________ executes a Java application.
Answer: java
What is the output of the following code?
int x = 0;
if (x < 4) {
x = x + 1;
}
System.out.println("x is " + x);
Answer: x is 1
Which of the following statements is true?
Answer: All of the above.
Which of the following statements is false?
Answer: Attributes are specified by the class’s methods.
Which of the following statements is false?
Answer: For objects to communicate effectively with one another, each must know how the other object
is implemented.

Java supports ________; collections of related methods that typically enable you to tell objects what to do,
but not how to do it (we’ll see an exception to this in Java SE 8).
Answer: interfaces
Mike Danielle Adaure
Consider the array:

s[0] = 7

s[1] = 0

s[2] = -12

s[3] = 9

s[4] = 10

s[5] = 3

s[6] = 6

The value of s[s[6] - s[5]] is:

Answer: 9 (POSSIBLE) 0| 3| 10 (INCORRECT)

Which of the following statements is true?


Answer: Syntax errors are caught by the compiler. Logic errors have effects at execution time.

Which of the following statements is false?


Answer: Each class can be used only once to build many objects.

Java was originally developed for :


Answer: Intelligent consumer devices.

Which statement is false?


Answer: A class is an instance of its object.

Which of the following is not a Java keyword?


Answer: next

To change to the completed application’s directory, we opened a command window and used the
________ command to change to the directory (also called a folder) for the Painter application.
Answer: cd

Consider the class below:


public class Test {
public static void main(String[] args) {
int[] a = {99, 22, 11, 3, 11, 55, 44, 88, 2, -3};

int result = 0;

for (int i = 0; i < a.length; i++) {


if (a[i] > 30) {
result += a[i];
}
}

System.out.printf("Result is: %d%n", result); }


}
The output of this Java program will be:
Answer: Result is: 286.
Mike Danielle Adaure
Which is the output of the following statements?

System.out.print("Hello ");
System.out.println("World");

Answer: Hello World


A programmer must do the following before using an array:
Answer: declare then create the array.
End-of-line comments that should be ignored by the compiler are denoted using
Answer: Two forward slashes (//).
Given the Java statement
int sum = number1 + number2;
which of the following statements is false?
Answer: It assigns the value of number1 to sum.
When an object is concatenated with a String, ________.

Answer: the object’s toString method is implicitly called to obtain the String representation of the object
The class extension on a file means that the file:
Answer: is produced by the Java compiler (javac).
Which of the following is the correct statement to return JAVA?
Answer: "Java".toUpperCase()
Which of the following data items are arranged from the smallest to the largest in the data hierarchy.
Answer: bits, characters, fields, records, files.
Which primitive type can hold the largest value?
Answer: double (POSSIBLE) long| int (INCORRECT)

Which of the following is not a primitive type?


Answer: String
Consider the code segment below. Which of the following statements is false?
int[] g;
g = new int[23];
Answer: The value of g[3] is -1.
Which of the following escape sequences represents a carriage return?
Answer: \r.
________ models software in terms similar to those that people use to describe real-world objects.
Answer: Object-oriented design
The expression "Java " + 1 + 2 + 3 evaluates to ________.
Answer: Java 123
A computer consists of various devices referred to as ________ (e.g., the keyboard, screen, mouse, hard
disks, memory, DVD drives and processing units).
Answer: hardware
What is the return value of "SELECT".substring(0, 5)?
Answer: "SELEC"
Which of the following initializer lists would correctly set the elements of array n?
Answer: int[] n = {1, 2, 3, 4, 5};.
What do the following statements do?
Mike Danielle Adaure
double[] array;
array = new double[14];
Answer: Create a double array containing 14 elements.

A decision symbol in an activity diagram takes the shape of a ________.


Answer: Diamond.

Which command executes the Java class file Welcome.class?


Answer: java Welcome

A new class of objects can be created conveniently by ________; the new class (called the ________) starts
with the characteristics of an existing class (called the ________), possibly customizing them and adding
unique characteristicsof its own.
Answer: inheritance, subclass, superclass

Which of the following is not an algorithm?


Answer: Textbook index.

What will be output after the following Java statements have been executed (assume all variables are of
type int)?
a = 4;
b = 12;
c = 37;
d = 51;

if (a < b) {
System.out.println("a < b");
}

if (a > b) {
System.out.println("a > b");
}

if (d <= c) {
System.out.println("d <= c");
}

if (c != d) {
System.out.println("c != d");
}
Answer: a<b
c != d
Which of the following code displays the area of a circle if the radius is positive?
Answer: if (radius > 0) System.out.println(radius * radius * 3.14159);

Which of the following statements is false?


Answer: In use today are more than a trillion general-purpose computers and trillions more Java-
enabled cellphones, smartphones and other handheld devices.

Constant variables also are called


Mike Danielle Adaure
Answer: named constants

Which of the following statements about arrays are true?


A. An array is a group of variables containing values that all have the same type.
B. Elements are located by index.
C. The length of an array c is determined by the expression c.length();.
D. The zeroth element of array c is specified by c[0].
Answer: A, B, D.

Which of the following is the shape of an action-state symbol?


Answer: Rectangle with left and right sides replaced with arcs curving outward.

You might also like