Name: 
 

Java Fall 2014



Multiple Choice
Identify the choice that best completes the statement or answers the question.
 

 1. 

What is the name of the file declaring the class named MyClass?
a.
MyClass
c.
MyClass.class
b.
myclass.java
d.
MyClass.java
 

 2. 

What is the output of the following code:

Circle c1 = new Circle(3);
Circle c2 = new Circle(3);
c1.setRadius(4);
System.out.println(c2.getRadius());
a.
3
c.
6
b.
8
d.
4
 

 3. 

Which statement best describes the portability characteristic of Java?
a.
It is easy to copy Java source code from one machine to another.
b.
The same Java class files will run on different operating systems without change.
c.
It is easy to compile Java source code on different operating systems.
d.
It is easy to change a Java program so that it will work on different operating systems.
 

 4. 

What term is used to refer to an instruction in a method?
a.
statement
c.
comment
b.
constant
d.
object
 

 5. 

What type of program can you use to enter your Java program?
a.
compiler
c.
spreadsheet
b.
editor
d.
database
 

 6. 

What is the output of the following Java statement?

System.out.println("4 + 6");
a.
10
c.
4
b.
46
d.
4 + 6
 

 7. 

What term is used to refer to the computer instructions that are executed by a CPU, which are specific to each CPU?
a.
virtual machine
c.
high-level code
b.
machine code
d.
instruction set
 

 8. 

What is the name of the type that denotes a string of characters?
a.
Characters
c.
charString
b.
char
d.
String
 

 9. 

To use a class in another package you need to ________ it.
a.
export
c.
rewrite
b.
overload
d.
import
 

 10. 

What is a Java library?
a.
A collection of Java source code that has been programmed and can be reused.
b.
A collection of books on Java.
c.
A collection of electronic documentation on Java.
d.
A collection of code that has been programmed and translated by someone else, ready for you to use in your program.
 

 11. 

What contains the instructions to initialize the instance variables of an object?
a.
constructor
c.
initializer
b.
access specifier
d.
type name
 

 12. 

A method may be called by specifying which 3 items in the specified order?
a.
method name, parameters, object
c.
object, method name, parameters
b.
object, parameters, method name
d.
class, parameters, method name
 

 13. 

Which of the following constructs a Circle of radius 3, assuming the construction parameter is the radius value?
a.
Circle(3).new
c.
new.Circle(3)
b.
new Circle(3)
d.
Circle(3)
 

 14. 

Evaluate the given pseudocode to calculate the weighted score for a student:
The average program score (program) = 92
The weight of programs (pgmWeight) = 40%
The average exam score (exams) = 85
The weight of exams(exWeight) = 60%

input program
input pgmWeight
input exams
input exWeight
output program*pgmWeight + exams*exWeight

What is the final output?
a.
89.20
c.
89.80
b.
87.80
d.
92.20
 

 15. 

What do static variables belong to?
a.
a method
c.
a class
b.
a package
d.
an object
 

 16. 

The object on which the method call is invoked provides input to the method, and is called a(n) _________________.
a.
interface
c.
implicit parameter
b.
procedure
d.
explicit parameter
 

 17. 

Evaluate the given pseudocode to calculate the efficiency of a vehicle's fuel consumption using the following test values:
The trip odometer reading (odometer) = 300
The amount to fill the gas tank (amount) = 15

input odometer
input amount
output odometer/amount

What is the final output?
a.
15
c.
30
b.
10
d.
20
 

 18. 

What is the name of the file created after a successful compilation of MyClass.java?
a.
MyClass.java
c.
myClass.class
b.
MyClass.class
d.
MyClass
 

 19. 

What does CPU stand for?
a.
Computer Programming Unit
c.
Central Processing Unit
b.
Computer Processing Unit
d.
Central Programming Unit
 

 20. 

What terminology describes a method that modifies the internal data of its implicit parameter?
a.
public
c.
mutator
b.
void
d.
accessor
 

 21. 

What is the nickname for the graphical user interface library in Java?
a.
Applet
c.
JComponent
b.
GUI
d.
Swing
 

 22. 

We want to change the BankAccount class so that all accounts will have a monthly fee.  When a BankAccount is created, its monthly fee is set and cannot be changed. The instance variable monthlyFee will hold the monthly fee.  Which of the following constructors properly sets the monthly fee to a default value of 20?
a.
public BankAccount (double initialBalance)
{
   balance = initialBalance;
   monthlyFee = 20;
}
b.
public BankAccount (double initialBalance)
{
   balance = initialBalance;
   double monthlyFee = 20;
}
c.
public BankAccount (double initialBalance)
{
   balance = initialBalance;
   monthlyFee = initialBalance - 20;
}
d.
public BankAccount (double initialBalance)
{
   balance = initialBalance - 20;
}
 

 23. 

Which method call represents the invocation of a method that does not have explicit parameters?
a.
greeting.replace("Hello", "Welcome");
b.
greeting.length
c.
greeting.length()
d.
System.out.println(greeting);
 

 24. 

The black boxes from which a program is manufactured are called ___.
a.
objects
c.
methods
b.
access specifiers
d.
instance variables
 

 25. 

Which of the following method calls illustrates the return value of a method as a parameter?
a.
greeting.length();
b.
greeting.println("Hello");
c.
System.out.println(length.greeting());
d.
System.out.println(greeting.length());
 

 26. 

Consider the following invocation of the deposit method:

mySavings.deposit(250);

What is the explicit parameter?
a.
There is no explicit parameter.
c.
250
b.
deposit
d.
mySavings
 

 27. 

Private instance variables ___.
a.
can only be accessed by methods of a different class
b.
can only be accessed by methods of the same class
c.
cannot be accessed by methods of the same class
d.
can only be accessed by the constructor of the class
 

 28. 

In the statement below, amount is referred to as the ____ parameter.

public void deposit(double amount)
a.
private
c.
explicit
b.
public
d.
implicit
 

 29. 

Assume that the following Java statement is contained in the main method of the class named Welcome:

   System.out.printLine("Welcome!");

What is the name of the file generated by the Java compiler?
a.
Welcome.class
c.
No file is generated due to an error.
b.
Welcome.java
d.
Welcome
 

 30. 

Identify the explicit parameter of the withdraw method of the BankAccount class.
a.
public
c.
balance
b.
double
d.
amount
 

 31. 

We want to create a class that represents a date.  A date has a day, month, and year.  For example, the date March 16, 2014 has the day 16, month 3, and year 2014. The basic framework of a date class is below:
public class Date
{
   private int day;
   private int month;
   private int year;
}
What should the body of the constructor be?
a.
day = d;
   month = m;
   year = y;
b.
d = day;
   m = month;
   y = year;
c.
int day = d;
   int month = m;
   int year = y;
d.
day = 1;
   month = 1;
   year = 1990;
 

 32. 

Which statement about identifiers is correct?
a.
Identifiers are not case sensitive.
b.
Spaces are permitted inside identifiers.
c.
Identifiers can use symbols such as ? or %.
d.
Identifiers can be made up of letters, digits, and the underscore (_) character.
 

 33. 

Which is a valid number literal?
a.
1x10^4
c.
3 1/2
b.
1E4
d.
10,000
 

 34. 

What is the JVM?
a.
A vital machine that never fails to run compiled Java code.
b.
A vital machine that compiles Java code into machine instructions.
c.
A virtual machine that runs compiled Java code on any CPU.
d.
A virtual machine that compiles Java code into machine instructions.
 

 35. 

When are local variables initialized?
a.
Local variables are initialized with a default value before a constructor is invoked.
b.
Local variables are initialized when the method is called.
c.
You must initialize local variables in a method body.
d.
You must initialize local variables in the constructor.
 

 36. 

Which memory type does not provide persistent storage?
a.
secondary storage
c.
primary storage
b.
hard disk
d.
DVD
 

 37. 

A step sequence that can be carried out in practice is ______________.
a.
unambiguous
c.
executable
b.
terminating
d.
documented
 

 38. 

What is a local variable?
a.
A variable that is declared in the header of a class.
b.
A variable that is declared in the body of the class.
c.
A variable that is declared in the header of a method.
d.
A variable that is declared in the body of a method.
 

 39. 

Which term is used to describe the name of a variable, method, or class?
a.
type
c.
identifier
b.
literal
d.
label
 

 40. 

Which of the following declares a sideLength instance variable for a Square class that stores an integer value?
a.
private integer sideLength;
c.
public integer sideLength
b.
private int sideLength;
d.
public static int sideLength;
 

 41. 

What statement is used to specify the value that a method gives back to its caller?
a.
new
c.
private
b.
public
d.
return
 

 42. 

Suppose that a computer virus infects your computer and corrupts the files you were going to submit for your current homework assignment. What precaution could have saved you from a disastrously bad grade for this assignment?
a.
Defragment the hard drive.
b.
Purchase an anti-virus program to remove the virus from your computer.
c.
Make regular backups of all your important files.
d.
Purchase an extended warranty for your computer.
 

 43. 

We want to create a class that represents a date.  A date has a day, month, and year.  For example, the date March 16, 2014 has the day 16, month 3, and year 2014. The basic framework of a date class is below:
public class Date
{
   private int day;
   private int month;
   private int year;
}
We want to create a specific date using code like:
Date first = new Date (16, 3, 2014);
//  Creates March 16, 2014

Date second = new Date (1, 9, 2013);
//  Creates September 1, 2013
Which of the constructor specifications below will allow this code to behave as desired?
a.
public void Date (int d, int m, int y)
b.
public init (int d, int m, int y)
c.
public Date (int d, int m, int y)
d.
public Date Date (int d, int m, int y)
 

 44. 

What do instance variables belong to?
a.
an object
c.
a method
b.
a class
d.
a package
 

 45. 

Which of the following declares a variable that will store a welcome message?
a.
String welcome;
c.
Char welcome;
b.
double welcome;
d.
int welcome;
 

 46. 

Which method checks whether a point lies within the rectangle?
a.
add
c.
translate
b.
getBounds
d.
contains
 

 47. 

What is the output of the following code:

int num1 = 6;
int num2 = 10;
num1 = num1 + num2;
num2 = num1 + num2;
System.out.println(num1 + ", " + num2);
a.
6, 10
c.
16, 22
b.
16, 16
d.
16, 26
 

 48. 

When a Java application starts, what is the name of the method that is executed?
a.
main
c.
begin
b.
start
d.
Main
 

 49. 

What is a storage location in the computer's memory called that has a type, name, and contents?
a.
identifier
c.
label
b.
literal
d.
variable
 

 50. 

What is the purpose of the following algorithm?

num = 0
Repeat the following steps for 10 times
input var1
   if var1 > num then
   num = var1
   end of if
end of repeat
print num
a.
To print out the 10 numbers
b.
To search for a particular number among 10 numbers
c.
To find the largest among 10 numbers
d.
To find the smallest among 10 numbers
 



 
Check Your Work     Start Over