You are on page 1of 1

 SHSEXAM 2222   Jang Bayot Glen

 BAED-PROG3112B-2222S
BAED-PROG3112B Programming (Java) NCIII Part 2
 Participants
Home / My courses / BAED-PROG3112B-2222S / SECOND QUARTER EXAM / SECOND QUARTER EXAM

 Badges

 Competencies
Started on Saturday, 10 June 2023, 10:23 AM Quiz navigation
State Finished 1 2 3 4 5 6 7 8 9
 Grades
Completed on Saturday, 10 June 2023, 10:51 AM
Time taken 27 mins 44 secs
 General 10 11 12 13 14 15 16 17 18
Marks 48.00/50.00
 FIRST QUARTER EXAM Grade 96.00 out of 100.00
19 20 21 22 23 24 25 26 27

 SECOND QUARTER EXAM Question 1 Where can local variables declared within a method’s body be used?
Correct 28 29 30 31 32 33 34 35 36

 Home
Mark 1.00 out a. Only within while or if statements within the method in which they were declared.
of 1.00
b. Only in that method between the line in which they were declared and the closing brace of that method.
37 38 39 40 41 42 43 44 45
Flag
 Dashboard
question
c. Same as (a), but not within while or if statements.
46 47 48 49 50
 Calendar d. Anywhere within the class.

 Private files Show one page at a time

Your answer is correct. Finish review


 My courses

 BAED-PROG3112B-2222S Question 2 The format specifier ________ is used to output values of type float or double. 
Correct
 BAED-STAT2112-2222S
Mark 1.00 out a. %d
of 1.00
 BAED-RSCH2111-2222S b. %fd
Flag
question
c. %r
 BAED-PEDH2112-2222S
d. %f

 BAED-FILI2112-2222S

 BAED-ENTR2122-2222S Your answer is correct.

 BAED-ENGL2112-2222S
Question 3 
Which expression is equivalent to if (!(grade == sentinelValue))?
 BAED-CPAR2122-2222S Correct

Mark 1.00 out a. if (grade !== sentinelValue)


of 1.00
b. ! if (grade !== sentinelValue)
Flag
question
c. if (grade != sentinelValue)

d. ! if (grade == sentinelValue)

Your answer is correct.

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

Mark 1.00 out


of 1.00 if (income > 3000) {

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


question
}
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. Income is greater than 3000 followed by Income is greater than 4000

d. Income is greater than 4000

e. no output

Your answer is correct.

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


Correct

Mark 1.00 out a. =!


of 1.00
b. ==
Flag
question
c. <=

d.       >

Your answer is correct.

Question 6 Analyze the following code:


Correct

Mark 1.00 out


of 1.00 boolean even = false;

Flag if (even = true) {


question
  System.out.println("It is even");
}

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

b. The program has a runtime error.

c. The program has a compile error.

d. The program runs fine, but displays nothing.

Your answer is correct.

Question 7 The following code displays ___________.


Correct

Mark 1.00 out


of 1.00 double temperature = 50;

Flag
question
if (temperature >= 100)

  System.out.println("too hot");
else if (temperature <= 40)
  System.out.println("too cold");

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

a. too cold

b. too hot too cold just right

c. just right

d. too hot

Your answer is correct.

Question 8 Which of the following is true? 


Incorrect

Mark 0.00 out a. All of the above.


of 1.00
b. Pseudocode is used to describe an algorithm.
Flag
question c. Pseudocode is used to describe executable statements that will eventually be translated by the programmer into a program.

d. Pseudocode is not an actual computer programming language.

Your answer is incorrect.

Question 9 Optional parentheses in expressions are said to be


Correct

Mark 1.00 out a. binary operators.


of 1.00
b. declared. 
Flag
question
c. implied.

d. redundant.

Your answer is correct.

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


Correct

Mark 1.00 out a. Constants.


of 1.00
b. Variables.
Flag
question
c. Expressions.

d. All of the above.

Your answer is correct.

Question 11 A static method can ________.


Correct

Mark 1.00 out a. manipulate only static fields in the same class directly
of 1.00
b. All of the above.
Flag
question
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.

Question 12 Which of the following statements is true?


Correct

Mark 1.00 out a. Compilers translate high-level language programs into machine language programs.
of 1.00
b. Interpreter programs typically use machine language as input.
Flag
question
c. Interpreted programs run faster than compiled programs.

d. None of the above.

Your answer is correct.

Question 13 What is the value of the following expression?


Correct
true || true && false
Mark 1.00 out
of 1.00

Flag
question a. false

b. true

Your answer is correct.

Question 14 What is output by the following Java code segment?


Correct
int temp = 180;
Mark 1.00 out
of 1.00

Flag while (temp != 80) {


question
   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 just right!

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

c. None of the above.

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

Your answer is correct.

Question 15 What is the value of result after the following Java statements execute (assume all variables are of type int)?
Correct
a = 4;
Mark 1.00 out
of 1.00 b = 12;

Flag c = 37;
question
d = 51;

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

a. 59

b. 119

c. 51

d. 127

Your answer is correct.

Question 16 What is output by the following Java code segment?


Incorrect
int temp = 180;
Mark 0.00 out
of 1.00

Flag if (temp > 90) {


question
   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. None of the above.

b. This porridge is too hot. 

c. This porridge is too cold.


This porridge is just right! 

d. This porridge is just right!

Your answer is incorrect.

Question 17 What is y after the following switch statement is executed?


Correct

Mark 1.00 out


of 1.00 int x = 3; int y = 4;

Flag switch (x + 3) {
question
  case 6:  y = 0;
  case 7:  y = 1;

  default: y += 1;
}

a. 3

b. 4

c. 1

d. 0

e. 2

Your answer is correct.

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

Mark 1.00 out a. number = 12;


of 1.00
b. int a;
Flag
question c. y = y + 2;

d. width = Integer.parseInt(input);

Your answer is correct.

Question 19 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. 
Correct

Mark 1.00 out a. reference


of 1.00
b. static 
Flag
question c. declared

d. source

Your answer is correct.

Question 20 What is the result value of c at the end of the following code segment?
Correct
int c = 8; 
Mark 1.00 out
of 1.00 c++; 

Flag ++c; 
question
c %= 5;

a. 0.

b. None of the above.

c. 3.

d. 1.

Your answer is correct.

Question 21 Which of the following statements is true?


Correct

Mark 1.00 out a. Constructors can specify parameters and return types.
of 1.00
b. Constructors can specify neither parameters nor return types.
Flag
question
c. Constructors cannot specify parameters but can specify return types.

d. Constructors can specify parameters but not return types.

Your answer is correct.

Question 22 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 ________. 
Correct

Mark 1.00 out a. zero


of 1.00
b. false
Flag
question
c. their default values.

d. null

Your answer is correct.

Question 23 Overloaded methods always have the same _________.


Correct

Mark 1.00 out a. return type


of 1.00
b. order of the parameters
Flag
question
c. number of parameters

d. method name

Your answer is correct.

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

Mark 1.00 out a. the argument list


of 1.00
b. the method modifier
Flag
question
c. the method name

d. the return type

Your answer is correct.

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

Mark 1.00 out a. parameterless


of 1.00
b. parameterized
Flag
question c. constructor

d. destructor

Your answer is correct.

Question 26 The empty statement is denoted by what symbol?


Correct

Mark 1.00 out a. This porridge is too cold.


of 1.00
This porridge is just right! 
Remove flag
b. Parentheses ()

b. Semicolon ;

c. Colon :

d. Braces {}

Your answer is correct.

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

Mark 1.00 out a. private methods


of 1.00
b. main
Flag
question
c. static methods

d. public methods

Your answer is correct.

Question 28 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
Correct creating an object of the class in which the method is declared.
Mark 1.00 out
of 1.00
a. stable
Flag
question b. private

c. static

d. public

Your answer is correct.

Question 29 Which statement below is  false?


Correct

Mark 1.00 out a. Structured programming requires four forms of control.


of 1.00
b. Structured programming promotes simplicity.
Flag
question
c. Structured programming produces programs that are easier to test.

d. Structured programming produces programs that are easier to modify

Your answer is correct.

Question 30 For the two code segments below:


Correct
Segment A
Mark 1.00 out
of 1.00 int q = 5;

Flag switch(q) {
question
   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

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: 

Your answer is correct.

Question 31 Any field declared with keyword ________ is constant.


Correct

Mark 1.00 out a. const


of 1.00
b. final
Flag
question
c. constant

d. static

Your answer is correct.

Question 32 An overloaded method is one that ________.


Correct

Mark 1.00 out a. has the same name and parameters, but a different return type as another method
of 1.00
b. has the same name as another method, but different parameters (by number, types or order of the types)
Flag
question c. has the same name and parameters as a method defined in another class

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

Your answer is correct.

Question 33 What is y displayed in the following code?


Correct

Mark 1.00 out


of 1.00 public class Test1 {

Flag   public static void main(String[] args) {


question
    int x = 1;

    int y = x = x + 1;
    System.out.println("y is " + y);
  }  
}

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

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

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

d. y is 0.

Your answer is correct.

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

Mark 1.00 out a. Pascal.


of 1.00
b. Basic.
Flag
question
c. COBOL.

d. Fortran.

Your answer is correct.

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

Mark 1.00 out a. !=


of 1.00
b. <
Flag
question
c. <<

d. =<

e. <=

Your answer is correct.

Question 36 Analyze the following code.


Correct

Mark 1.00 out


of 1.00 boolean even = false;

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

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

b. The code displays nothing.

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

d. The code displays It is even!

Your answer is correct.

Question 37 What is output by the following Java code segment?


Correct
  int temp = 200;
Mark 1.00 out
of 1.00

Flag if (temp > 90) {


question
   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. None of the above.

b. This porridge is just right!

c. This porridge is too hot.

d. This porridge is too cold.

Your answer is correct.

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

Mark 1.00 out a.  B


of 1.00
b. A1
Flag
question c. Illegal expression

d. 66

Your answer is correct.

Question 39
How many times is the body of the loop below executed?
Correct
int counter = 1;
Mark 1.00 out
of 1.00

Flag while (counter > 20) {


question
        // body of loop

        counter = counter - 1;


}

a. 0.

b. 19.

c. 20.

d. 21.

Your answer is correct.

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

Mark 1.00 out a. core


of 1.00
b. central processing unit
Flag
question
c. colonel.

d. kernel.

Your answer is correct.

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


Correct

Mark 1.00 out a. %s


of 1.00
b. %d
Flag
question c. %int

d. %n

Your answer is correct.

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

Mark 1.00 out a. Machine languages.


of 1.00
b. High-Level languages.
Flag
question c. Spoken languages.

d. Assembly languages.

Your answer is correct.

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

Mark 1.00 out a. break statement.


of 1.00
b. continue statement.
Flag
question
c. Any of the above.

d. return statement.

Your answer is correct.

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

Mark 1.00 out a.  All of the above increment val by 3.


of 1.00
b. val += 3;
Flag
question
c. c = 3; 
val = val + (c == 3 ? 2 : 3);

d. val = val + 1;
val = val + 1;
val = val + 1;

Your answer is correct.

Question 45 For the code segment below:


Correct

Mark 1.00 out


of 1.00 switch(q) {

Flag    case 1:
question
    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. 2.

b. 3. 

c. 1.

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

Your answer is correct.

Question 46 In Java, the word true is ________.


Correct

Mark 1.00 out a. same as value 1


of 1.00
b.  a Java keyword
Flag
question
c. a Boolean literal 

d. same as value 0

Your answer is correct.

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

Mark 1.00 out a. private 


of 1.00
b. static 
Flag
question
c. masked 

d. secure 

Your answer is correct.

Question 48 Which of the following operators associates from left to right?


Correct

Mark 1.00 out a. /


of 1.00
b. ?:
Flag
question
c. =

d. %=

Your answer is correct.

Question 49 The equal comparison operator in Java is __________.


Correct

Mark 1.00 out a. !=


of 1.00
b. <>
Flag
question
c. ==

d. ^=

Your answer is correct.

Question 50 Local variables must be ________.


Correct

Mark 1.00 out a. initialized before their values are used in an expression.
of 1.00
b. initialized when they're declared.
Flag
question
c. declared and initialized in two steps.

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

Your answer is correct.

Finish review

◄ FIRST QUARTER EXAM Jump to...

You are logged in as ALVIC JULIUS SUBINGSUBING (Log out)


BAED-PROG3112B-2222S
Data retention summary
Get the mobile app

You might also like