Prog 2 NDQ
Prog 2 NDQ
declaration.
a.
the argument list
b.
the method name
c.
the method modifier
d.
the return type
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.
2.
b.
1.
c.
Any integer less than 1 and greater than or equal to 4.
d.
3.
a.
parameterless
b.
destructor
c.
parameterized
d.
constructor
b.
destructor
c.
parameterized
d.
constructor
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.
false
b.
null
c.
zero
d.
their default values.
a.
Constructors can specify parameters but not return types.
b.
Constructors can specify parameters and return types.
c.
Constructors cannot specify parameters but can specify return types.
d.
Constructors can specify neither parameters nor return types.
a.
too cold
b.
too hot too cold just right
c.
too hot
d.
just right
b.
Pseudocode is used to describe executable statements that will eventually be translated by the
programmer into a program.
c.
Pseudocode is used to describe an algorithm.
d.
All of the above.
a.
%=
b.
=
c.
?:
d.
/
a.
static
b.
constant
c.
final
d.
const
a.
%n
b.
%d
c.
%int
d.
%s
What is the result value of c at the end of the following code segment?
int c = 8;
c++;
++c;
c %= 5;
a.
3.
b.
None of the above.
c.
1.
d.
0.
To exit out of a loop completely, and resume the flow of control at the next statement after
the loop, use a _______.
a.
return statement.
b.
break statement.
c.
Any of the above.
d.
continue statement.
a.
This porridge is too cold.
b.
This porridge is just right!
c.
This porridge is too hot.
d.
None of the above.
The software that contains the core components of the operating system is the ________.
a.
kernel.
b.
colonel.
c.
central processing unit
d.
core
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.
127
b.
59
c.
119
d.
51
a.
has the same name and parameters, but a different return type as another method
b.
has the same name as another method, but different parameters (by number, types or order
of the types)
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
a.
redundant.
b.
binary operators.
c.
implied.
d.
declared.
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 2 because x + 1 is assigned to x and then x is assigned to y.
d.
y is 1 because x is assigned to y first.
a.
Structured programming produces programs that are easier to test.
b.
Structured programming promotes simplicity.
c.
Structured programming produces programs that are easier to modify
d.
Structured programming requires four forms of control.
// 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 hot.
b.
This porridge is too cold.
This porridge is just right!
c.
This porridge is just right!
d.
None of the above.
a.
Constants.
b.
All of the above.
c.
Variables.
d.
Expressions.
// 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 too cold! This porridge is just right!
d.
This porridge is just right!
a.
The code displays It is even!
b.
The code displays nothing.
c.
The code is wrong. You should replace if (even) with if (even = true).
d.
The code is wrong. You should replace if (even) with if (even == true).
A static method can ________.
a.
manipulate only static fields in the same class directly
b.
All of the above.
c.
call only other static methods of the same class directly
d.
be called using the class name and a dot (.)
a.
21.
b.
19.
c.
20.
d.
0.
Which of the following statements does not alter the value stored in a memory location?
a.
y = y + 2;
b.
width = Integer.parseInt(input);
c.
int a;
d.
number = 12;
a.
masked
b.
secure
c.
static
d.
private
Which of the following code segments does not increment val by 3:
a.
All of the above increment val by 3.
b.
c = 3;
val = val + (c == 3 ? 2 : 3);
c.
val += 3;
d.
val = val + 1;
val = val + 1;
val = val + 1;
Which of the following languages is used primarily for scientific and engineering
applications?
a.
COBOL.
b.
Fortran.
c.
Basic.
d.
Pascal.
The empty statement is denoted by what symbol?
a.
This porridge is too cold.
This porridge is just right!
b. Parentheses ()
b.
Colon :
c.
Semicolon ;
d.
Braces {}
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.
public
b.
static
c.
private
d.
stable
In Java, the word true is ________.
a.
a Boolean literal
b.
a Java keyword
c.
same as value 1
d.
same as value 0
a.
false
b.
true
You must call most methods other than ________ explicitly to tell them to perform their tasks.
a.
static methods
b.
public methods
c.
main
d.
private methods
a.
==
b.
<>
c.
^=
d.
!=
Note that the Unicode for character A is 65. The expression "A" + 1 evaluates to ________.
a.
A1
b.
66
c.
B
d.
Illegal expression
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.
1
c.
4
d.
3
e.
2
a.
Income is greater than 4000
b.
Income is greater than 3000
c.
no output
d.
Income is greater than 4000 followed by Income is greater than 3000
e.
Income is greater than 3000 followed by Income is greater than 4000
a.
The program runs fine and displays It is even.
b.
The program has a compile error.
c.
The program has a runtime error.
d.
The program runs fine, but displays nothing.
The format specifier ________ is used to output values of type float or double.
a.
%fd
b.
%d
c.
%f
d.
%r
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");
}
a.
The output for Segment A is:
5
default
b.
The output for Segment B is:
4
c.
The output for Segment A is:
default
d.
The output for Segment B is:
45 default
Which of the following is not one of the three general types of computer languages?
a.
Assembly languages.
b.
Machine languages.
c.
Spoken languages.
d.
High-Level languages.
a.
=!
b.
==
c.
<=
d.
>
a.
declared and initialized in two steps.
b.
declared at the top of the method’s body.
c.
initialized before their values are used in an expression.
d.
initialized when they're declared.
a.
if (grade !== sentinelValue)
b.
if (grade != sentinelValue)
c.
! if (grade !== sentinelValue)
d.
! if (grade == sentinelValue)
a.
!=
b.
=<
c.
<<
d.
<
e.
<=
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.
declared
b.
static
c.
source
d.
reference
Overloaded methods always have the same _________.
a.
number of parameters
b.
method name
c.
return type
d.
order of the parameters
a.
Only in that method between the line in which they were declared and the closing brace of
that method.
b.
Anywhere within the class.
c.
Only within while or if statements within the method in which they were declared.
d.
Same as (a), but not within while or if statements.
a.
Compilers translate high-level language programs into machine language programs.
b.
Interpreter programs typically use machine language as input.
c.
None of the above.
d.
Interpreted programs run faster than compiled programs.