0% found this document useful (0 votes)
183 views26 pages

Prog 3112

This document is a review of a second quarter exam taken by the student. It consists of 16 multiple choice questions covering topics like Java code segments, loop statements, data types, and computer language types. The student answered 14 questions correctly and 2 questions incorrectly, achieving a score of 47 out of 50 or 94% overall.

Uploaded by

prettykeonii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
183 views26 pages

Prog 3112

This document is a review of a second quarter exam taken by the student. It consists of 16 multiple choice questions covering topics like Java code segments, loop statements, data types, and computer language types. The student answered 14 questions correctly and 2 questions incorrectly, achieving a score of 47 out of 50 or 94% overall.

Uploaded by

prettykeonii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Home / My courses / BAED-PROG3112-2312S / SECOND QUARTER EXAM / SECOND QUARTER EXAM

Started on Monday, 15 January 2024, 2:39 PM


State Finished
Completed on Monday, 15 January 2024, 2:55 PM
Time taken 15 mins 34 secs
Marks 47.00/50.00
Grade 94.00 out of 100.00

Question 1
Correct

Mark 1.00 out of 1.00

The following code displays ___________.

double temperature = 50;

if (temperature >= 100)


System.out.println("too hot");

else if (temperature <= 40)

System.out.println("too cold");

else

System.out.println("just right");

a. just right

b. too hot too cold just right

c. too cold

d. too hot

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 1/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 2

Correct

Mark 1.00 out of 1.00

For the code segment below:

switch(q) {

case 1:
System.out.println("apple");

break;

case 2:

System.out.println("orange");

break;
case 3:

System.out.println("banana");

break;

case 4:

System.out.println("pear");
case 5:

System.out.println("grapes");

default:

System.out.println("kiwi");

Which of the following values for q will result in kiwi being included in the output?

a. Any integer less than 1 and greater than or equal to 4.

b. 3.

c. 1.

d. 2.

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 2/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 3

Correct

Mark 1.00 out of 1.00

What is y displayed in the following code?

public class Test1 {

public static void main(String[] args) {


int x = 1;

int y = x = x + 1;

System.out.println("y is " + y);

a. y is 0.

b. The program has a compile error since x is redeclared in the statement int y = x = x + 1.

c. y is 1 because x is assigned to y first.

d. y is 2 because x + 1 is assigned to x and then x is assigned to y.

Your answer is correct.

Question 4
Correct

Mark 1.00 out of 1.00

What is the result value of c at the end of the following code segment?
int c = 8;

c++;

++c;

c %= 5;

a. None of the above.

b. 0.

c. 3.

d. 1.

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 3/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 5

Correct

Mark 1.00 out of 1.00

Which expression is equivalent to if (!(grade == sentinelValue))?

a. if (grade !== sentinelValue)

b. if (grade != sentinelValue)

c. ! if (grade !== sentinelValue)

d. ! if (grade == sentinelValue)

Your answer is correct.

Question 6
Correct

Mark 1.00 out of 1.00

Which of the following languages is used primarily for scientific and engineering applications?

a. Basic.

b. COBOL.

c. Fortran.

d. Pascal.

Your answer is correct.

Question 7
Correct

Mark 1.00 out of 1.00

Local variables must be ________.

a. initialized when they're declared.

b. declared and initialized in two steps.

c. initialized before their values are used in an expression.

d. declared at the top of the method’s body.

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 4/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 8

Correct

Mark 1.00 out of 1.00

Which of the following statements does not alter the value stored in a memory location?

a. int a;

b. width = Integer.parseInt(input);

c. number = 12;

d. y = y + 2;

Your answer is correct.

Question 9
Correct

Mark 1.00 out of 1.00

Which of the following code segments does not increment val by 3:

a. c = 3; 

val = val + (c == 3 ? 2 : 3);

b. val += 3;

c. val = val + 1;

val = val + 1;

val = val + 1;

d. All of the above increment val by 3.

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 5/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 10

Incorrect

Mark 0.00 out of 1.00

What is output by the following Java code segment?

int temp = 200;

if (temp > 90) {


System.out.println("This porridge is too hot.");

if (temp < 70) {

System.out.println("This porridge is too cold.");


}

if (temp == 80) {

System.out.println("This porridge is just right!");

a. This porridge is too hot.

b. None of the above. 

c. This porridge is too cold.

d. This porridge is just right!

Your answer is incorrect.

Question 11
Correct

Mark 1.00 out of 1.00

To exit out of a loop completely, and resume the flow of control at the next statement after the loop, use a _______.

a. continue statement.

b. break statement.

c. return statement.

d. Any of the above.

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 6/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 12

Correct

Mark 1.00 out of 1.00

Which of the following is not one of the three general types of computer languages?

a. Machine languages.

b. Spoken languages.

c. High-Level languages.

d. Assembly languages.

Your answer is correct.

Question 13
Correct

Mark 1.00 out of 1.00

A static method can ________.

a. All of the above.

b. manipulate only static fields in the same class directly

c. be called using the class name and a dot (.)

d. call only other static methods of the same class directly

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 7/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 14

Correct

Mark 1.00 out of 1.00

Analyze the following code.

boolean even = false;

if (even) {
System.out.println("It is even!");

a. The code is wrong. You should replace if (even) with if (even = true).

b. The code displays It is even!

c. The code displays nothing.

d. The code is wrong. You should replace if (even) with if (even == true).

Your answer is correct.

Question 15
Correct

Mark 1.00 out of 1.00

Which of the following operators associates from left to right?

a. /

b. =

c. %=

d. ?:

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 8/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 16

Correct

Mark 1.00 out of 1.00

A key part of enabling the JVM to locate and call method main to begin the app’s execution is the ________ keyword, which indicates
that main can be called without first creating an object of the class in which the method is declared.

a. private

b. public

c. stable

d. static

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 9/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 17

Incorrect

Mark 0.00 out of 1.00

For the two code segments below:

Segment A

int q = 5;

switch(q) {
case 1:

System.out.println(1);

case 2:

System.out.println(2);

case 3:
System.out.println(3);

case 4:

System.out.println(4);

case 5:

System.out.println(5);
default:

System.out.println("default");

Segment B

q = 4;
switch(q) {

case 1:

System.out.println(1);

case 2:

System.out.println(2);
case 3:

System.out.println(3);

case 4:

System.out.println(4);

case 5:
System.out.println(5);

default:

System.out.println("default");

Which of the following statements is true?

a. The output for Segment A is:

default

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 10/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

b. The output for Segment A is:

5
default

c. The output for Segment B is: 

45 default

d. The output for Segment B is:


4

Your answer is incorrect.

Question 18
Correct

Mark 1.00 out of 1.00

The format specifier ________ is used to output values of type float or double.

a. %r

b. %fd

c. %f

d. %d

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 11/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 19

Correct

Mark 1.00 out of 1.00

The empty statement is denoted by what symbol?

a. Semicolon ;

b. Braces {}

c. Colon :

d. This porridge is too cold.

This porridge is just right!

b. Parentheses ()

Your answer is correct.

Question 20

Correct

Mark 1.00 out of 1.00

Any field declared with keyword ________ is constant.

a. const

b. constant

c. static

d. final

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 12/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 21

Correct

Mark 1.00 out of 1.00

If a class does not define constructors, the compiler provides a default constructor with no parameters, and the class’s instance
variables are initialized to ________.

a. null

b. their default values.

c. false

d. zero

Your answer is correct.

Question 22
Correct

Mark 1.00 out of 1.00

Which of the following statements is true?

a. Interpreted programs run faster than compiled programs.

b. None of the above.

c. Interpreter programs typically use machine language as input.

d. Compilers translate high-level language programs into machine language programs.

Your answer is correct.

Question 23
Correct

Mark 1.00 out of 1.00

What is the value of the following expression?

true || true && false

a. true

b. false

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 13/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 24

Correct

Mark 1.00 out of 1.00

How many times is the body of the loop below executed?


int counter = 1;

while (counter > 20) {


// body of loop

counter = counter - 1;

a. 20.

b. 21.

c. 0.

d. 19.

Your answer is correct.

Question 25
Correct

Mark 1.00 out of 1.00

Types in Java are divided into two categories. The primitive types are boolean, byte, char, short, int, long, float and double. All other
types are ________ types.

a. source

b. static

c. reference

d. declared

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 14/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 26

Correct

Mark 1.00 out of 1.00

What is output by the following Java code segment?

int temp = 180;

while (temp != 80) {


if (temp > 90) {

System.out.print("This porridge is too hot! ");

// cool down

temp = temp – (temp > 150 ? 100 : 20);


}

else {

if (temp < 70) {

System.out.print("This porridge is too cold! ");

// warm up

temp = temp + (temp < 50 ? 30 : 20);

if (temp == 80) {

System.out.println("This porridge is just right!");

a. This porridge is too hot! This porridge is just right!

b. None of the above.

c. This porridge is just right!

d. This porridge is too cold! This porridge is just right!

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 15/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 27

Correct

Mark 1.00 out of 1.00

Optional parentheses in expressions are said to be

a. declared.

b. binary operators.

c. redundant.

d. implied.

Your answer is correct.

Question 28
Correct

Mark 1.00 out of 1.00

Suppose income is 4001, what is the output of the following code?

if (income > 3000) {

System.out.println("Income is greater than 3000");

}
else if (income > 4000) {

System.out.println("Income is greater than 4000");

a. Income is greater than 3000

b. Income is greater than 4000 followed by Income is greater than 3000

c. no output

d. Income is greater than 4000

e. Income is greater than 3000 followed by Income is greater than 4000

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 16/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 29

Correct

Mark 1.00 out of 1.00

The software that contains the core components of the operating system is the ________.

a. core

b. central processing unit

c. kernel.

d. colonel.

Your answer is correct.

Question 30
Correct

Mark 1.00 out of 1.00

The "less than or equal to" comparison operator in Java is __________.

a. <

b. !=

c. =<

d. <<

e. <=

Your answer is correct.

Question 31
Correct

Mark 1.00 out of 1.00

Which statement below is false?

a. Structured programming produces programs that are easier to test.

b. Structured programming requires four forms of control.

c. Structured programming promotes simplicity.

d. Structured programming produces programs that are easier to modify

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 17/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 32

Correct

Mark 1.00 out of 1.00

The equal comparison operator in Java is __________.

a. ^=

b. <>

c. ==

d. !=

Your answer is correct.

Question 33
Correct

Mark 1.00 out of 1.00

Overloaded methods always have the same _________.

a. method name

b. return type

c. order of the parameters

d. number of parameters

Your answer is correct.

Question 34
Correct

Mark 1.00 out of 1.00

Declaring instance variables ________ is known as data hiding or information hiding.

a. masked

b. private 

c. secure

d. static

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 18/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 35

Correct

Mark 1.00 out of 1.00

What is output by the following Java code segment?

int temp = 180;

if (temp > 90) {


System.out.println("This porridge is too hot.");

// cool down

temp = temp – (temp > 150 ? 100 : 20);

}
else {

if (temp < 70) {

System.out.println("This porridge is too cold.");

// warm up
temp = temp + (temp < 50 ? 30 : 20);

if (temp == 80) {

System.out.println("This porridge is just right!");


}

a. This porridge is too cold.

This porridge is just right!

b. This porridge is too hot.

c. None of the above.

d. This porridge is just right!

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 19/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 36

Correct

Mark 1.00 out of 1.00

You must call most methods other than ________ explicitly to tell them to perform their tasks.

a. public methods

b. private methods

c. main

d. static methods

Your answer is correct.

Question 37
Correct

Mark 1.00 out of 1.00

Which of the following is true?

a. Pseudocode is used to describe executable statements that will eventually be translated by the programmer into a program.

b. Pseudocode is used to describe an algorithm.

c. All of the above.

d. Pseudocode is not an actual computer programming language.

Your answer is correct.

Question 38
Correct

Mark 1.00 out of 1.00

To declare a method as static, place the keyword static before ________ in the method’s declaration.

a. the method name

b. the method modifier

c. the return type

d. the argument list

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 20/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 39

Correct

Mark 1.00 out of 1.00

An overloaded method is one that ________.

a. has the same name and parameters, but a different return type as another method

b. has the same name and parameters as a method defined in another class

c. has the same name as another method, but different parameters (by number, types or order of the types)

d. has a different name than another method, but the same parameters

Your answer is correct.

Question 40
Correct

Mark 1.00 out of 1.00

The format specifier ________ is a placeholder for an int value.

a. %int

b. %s

c. %d

d. %n

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 21/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 41

Correct

Mark 1.00 out of 1.00

What is y after the following switch statement is executed?

int x = 3; int y = 4;

switch (x + 3) {
case 6: y = 0;

case 7: y = 1;

default: y += 1;

a. 0

b. 4

c. 1

d. 2

e. 3

Your answer is correct.

Question 42
Correct

Mark 1.00 out of 1.00

Each of the following is a relational or equality operator except:

a. <=

b. =!

c. >

d. ==

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 22/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 43

Correct

Mark 1.00 out of 1.00

In Java, the word true is ________.

a. same as value 0

b. a Boolean literal 

c. same as value 1

d. a Java keyword

Your answer is correct.

Question 44
Incorrect

Mark 0.00 out of 1.00

Which of the following statements is true?

a. Constructors can specify neither parameters nor return types. 

b. Constructors cannot specify parameters but can specify return types.

c. Constructors can specify parameters and return types.

d. Constructors can specify parameters but not return types.

Your answer is incorrect.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 23/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 45

Correct

Mark 1.00 out of 1.00

What is the value of result after the following Java statements execute (assume all variables are of type int)?

a = 4;

b = 12;

c = 37;
d = 51;

result = d % a * c + a % b + a;

a. 119

b. 51

c. 127

d. 59

Your answer is correct.

Question 46
Correct

Mark 1.00 out of 1.00

Where can local variables declared within a method’s body be used?

a. Only within while or if statements within the method in which they were declared.

b. Anywhere within the class.

c. Only in that method between the line in which they were declared and the closing brace of that method.

d. Same as (a), but not within while or if statements.

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 24/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 47

Correct

Mark 1.00 out of 1.00

Note that the Unicode for character A is 65. The expression "A" + 1 evaluates to ________.

a. A1

b. B

c. 66

d. Illegal expression

Your answer is correct.

Question 48
Correct

Mark 1.00 out of 1.00

Java requires a ________ call for every object that’s created.

a. parameterless

b. parameterized

c. constructor

d. destructor

Your answer is correct.

Question 49
Correct

Mark 1.00 out of 1.00

Which of the following can be an argument to a method?

a. Variables.

b. Constants.

c. All of the above.

d. Expressions.

Your answer is correct.

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 25/26
1/17/24, 10:54 AM SECOND QUARTER EXAM: Attempt review

Question 50

Correct

Mark 1.00 out of 1.00

Analyze the following code:

boolean even = false;

if (even = true) {
System.out.println("It is even");

a. The program runs fine, but displays nothing.

b. The program has a compile error.

c. The program has a runtime error.

d. The program runs fine and displays It is even.

Your answer is correct.

◄ FIRST QUARTER EXAM

Jump to...

https://shsexam.amaesonline.com/2312/mod/quiz/review.php?attempt=59474&cmid=268&showall=1 26/26

You might also like