Looks like no one added any tags here yet for you.
Inheritance is the process of sharing methods and instance variables between a base class
and its subclasses (T/F).
True
The name of the text file with Java source code must match the name of the program with a
.class extension (T/F).
False
Both for loops and while loops can be used as count-controlled loops (T/F).
True
It is illegal to declare several variables in a single declaration, i.e. int a, b, c;
False
m++, m=m+1, and m+=1 are all equivalent expressions (T/F).
True
The assignment operator ( = ) and equal to operator ( == ) can be used interchangeably (T/F).
False
A while loop will always execute at least once (T/F).
False
The counter in a for loop is updated at the beginning of the loop (T/F).
False
It is illegal to declare the loop control variable inside the for loop header (T/F).
False
The for statement combines counter initialization, condition test and counter update into a single expression (T/F).
True
It is usually safer to use the == or != operators in loops, rather than the other logical operators (T/F).
False
The identity of an object is simply the variable that references the object (T/F).
False
A class's implementation details can be changed radically without affecting any of its clients provided its interface remains the same (T/F).
True
The keyword public indicates that the class is accessible to all potential clients (T/F).
True
Constructors do not have return types, but all other methods do (T/F).
True
A class can include only one constructor (T/F).
False
A method can only have one return statement (T/F).
False
The OR operand evaluates to false if one operand is false (T/F).
False
Nested if statements offer an alternative to deal with a programs logical complexity (T/F).
True
Java uses complete evaluation, in which all parts of a Boolean expression are always evaluated (T/F).
False
Consider the following code segment:
int x = 7;
int y = 3;
if ( (x<10) && (y<0) )
System.out.println("Value is: " +x*y);
else
System.out.println("Value is: " + x/y);
Value is: 2
Assume that a and b have been defined and initialized as int values. The expression
!(! (a!=b) && (b>7))
is equivalent to which of the following?
(a != b) || (b <= 7)
Consider the following code segment.
int sum = 0;
int k =1;
while (sum < 12 || k<4)
sum += k;
System.out.println(sum);
What is printed as a result of executing the code segment?
Nothing is printed due to an infinite loop.
Consider the following code segment.
int num = 2574;
int result = 0;
while (num > 0) {
result = result * 10 + num % 10;
num /= 10;
}
System.out.println(result);
What is printed as a result of executing the code segment?
4752
Consider the following method.
public void test (int x) {
int y;
if (x % 2 ==0)
y=3;
else if (x>9)
y=5;
else
y = 1;
System.out.println("y = " + y);
}
Which of the following test data sets would test each possible output for the method?
8, 9, 11
Which of the following statements will result in a syntax error?
Integer x = "123";
What is the result when the following code segment is compiled and executed?
int m =4, n = 5;
double d = Math.sqrt( (m + n)/2);
System.out.println(d);
2.0
Given that x is true, y is true, and z is false, which of the following expressions will evaluate to false?
a. (X&&Y) || Z
b. (X || Y) && Z
c. Y || (X && Z)
d. X || (Y && Z)
e. X && (Y || Z)
b. (X || Y) && Z
What is the output of the following program segment?
int sum = 0, d= -1;
for (int count = 10; count >0; count--)
{
sum +=d;
if (d > 0)
d++;
else
d--;
d = -d;
}
System.out.println(sum);
5
What is the output of the following program segment?
int num = 5;
while (num >= 0)
{
num -= 2;
}
System.out.prinln(num);
-1
The following code segment is supposed to calculate and display 1 + 2 + ... + 20:
int count = 0, sum = 0;
while (count <20)
{
sum += count;
}
System.out.println(sum);
Which statement best displayed describes the result:
a. The total displayed will be correct.
b. The total displayed will be 20 too small.
c. The output will be the number 0.
d. The output will be the number 20.
e. There will be no output because the program goes into an infinite loop.
e. There will be no output because the program goes into an infinite loop.
What is the output of the following program segment?
int a = 3;
int b = 4;
int c = 0;
if ( a==b && b/c == 1)
{
c = a*b;
}
else
{
c = a + b*c;
System.out.println(c);
}
3
Which of the following statements about constructors are NOT true?
a. All constructors must have the same name as the class they are in
b. Constructors' return type must be declared void
c. a class may have a constructor that takes no parameters
d. a constructor is invoked when a program creates an object with the new keyword
e. Constructors should not have a return type
b. Constructors' return type must be declared void
110 base 2 is equivalent to what base 10 number?
6
A byte's location in memory is called its:
address
What defines or describes a list of data resources and rules of behavior?
class
In Object Oriented Programming objects work together by asking each other for services by
sending what to each other?
messages
When different types of objects respond to the same message differently, it is referred to as:
polymorphism
Combining the description of resources and behaviors into a single software entity is called:
encapsulation
The Java compiler translates Java source code into:
Java byte code
To run Java byte code on a particular computer you must install what on that computer?
Java Virtual Machine
What is the name of an object that knows how to display or print characters in a terminal
window?
System.out
What character is the method selector operator in Java?
period ( . )
What are the three steps to entering a program into a computer and running it?
Edit, Compile, Execute
The statement telling the Java compiler where to find a complete specification of a class is:
import
The Java compiler will ignore everything after what symbol?
//
What is the Java mechanism for repeating a group of statements?
for loop
What is the set of all the words and symbols in the Java programming language?
Vocabulary
Which of the following is NOT a primitive data type in Java?
string
How many numeric data types does Java include?
6
Which keyword in Java declares a variable whose value cannot change?
final
What is the string concatenation operator?
+
Which of the following is the escape sequence for a newline?
\n
What keyword indicates a method does not return a value?
void
Which of the following user-defined symbols is invalid?
9innings
In the statement import x.y.z; what does the x represent?
the name of the overall package
Using the same name for two different methods is called:
overloading
Which of the following methods is NOT included in the Math class?
readInt
Which of the following values could be returned from Random.nextInt(10)?
7
What type of expression returns either true or false?
Boolean
Which statement provides a looping mechanism that executes statements repeatedly as long as some condition is true?
while
How many times will the following loop execute?
int counter = 2;
while ( counter < 10 ){
counter += 2;
4
Which statement allows a loop to terminate before the loop condition is false?
break
The process of creating a new object is called:
instantiation
Java deletes objects from memory in a process called:
garbage collection
Which characteristic of an object says that at any moment its instance variables have particular values.
state
What is the list of the methods supported by the server referred to as?
interface
Messages that change an object's state are called:
mutators
What is the name of a method that indicates how to initialize a new object?
constructor
What are activated when the keyword new is used and at no other time.
constructors
A method whose implementing code is omitted is called a:
stub
The ________ of a variable is that region of the program within which it can validly appear in lines of code.
scope
The _________ of a variable is the period during which it can be used.
lifetime
If the operator AND is used, which of the following will make the whole condition true?
both operands true
Which of the following is the Java symbol for logical AND?
&&
A program that tolerates errors in user inputs and recovers gracefully is:
robust
In general, how many combinations of true and false are there for n operands in a truth table.
2^n
What is the symbol for the NOT operator in Java?
!
Which of the following Boolean expressions is equivalent to: !( p && q )
!p || !q
The approach in which evaluation of a Boolean expression stop as soon as possible is called:
short-circuit evaluation