Exam #1 Computer Programming Math-140
Suppose that a client performs an intermixed sequence of (queue) enqueue and dequeue operations. The enqueue operations put the integers 0 through 9 in order onto the queue; the dequeue operations print out the return value. Which of the following sequence(s) could not occur? 4 6 8 7 5 3 2 9 0 1
False
The public access specifier for a field indicates that the field may not be accessed by statements outside the class.
False
The term "default constructor" is applied to the first constructor written by the author of the class.
False
Which of the following statements opens a file named MyFile.txt and allows you to read data from it?
File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);
The java.lang package is automatically imported into all Java programs.
True
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
True
When you open a file with the PrintWriter class, the class can potentially throw an IOException.
True
When you pass the name of a file to the PrintWriter constructor and the file already exists, it will be erased and a new empty file with the same name will be created.
True
The following statement is an example of ________.import java.util.Scanner;
an explicit import statement
All fields declared in an interface ________.
are treated as final and static
Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.
methods
Most of the programming languages used today are ________.
object-oriented
A constructor is a method that ________.
performs initialization or setup operations
When you work with a ________, you are using a
primitive variable
All methods specified by an interface are ________.
public
Which of the following statements correctly specifies two interfaces?
public class ClassA implements Interface1, Interface2
Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops is the correct way to read data from the file until the end of the file is reached?
while (inputFile.hasNext()) { ... }
Consider a queue named myList 12, 24, 48 (first item is 12 and last item is 48) , where will the new item 72 be enqueued?
After 48
A method that gets a value from a class's field but does not change it is known as a mutator method.
False
In the following statement, which is the interface?public class ClassA extends ClassB implements ClassC
ClassC
________ refers to combining data and code into a single object.
Encapsulation
Methods that operate on an object's fields are called ________.
Instance methods.
Java allows you to create objects of the ________ class in the same way you would create primitive variables.
String
Which of the following statements will create a reference, str, to the String "Hello, World"?
String str = "Hello, World";
A class is not an object. It is a description of an object.
True
A constructor is a method that is automatically called when an object is created.
True
A file must always be opened before using it and closed when the program is finished using it.
True
A method that stores a value in a class's field or in some other way changes the value of a field is known as a mutator method.
True
An access specifier indicates how a class may be accessed.
True
An interface is a group of related methods with empty bodies.
True
An object can store data
True
Implementing an interface makes a class to become more formal about the behavior it promises to provide.
True
Suppose that a client performs an intermixed sequence of (queue) enqueue and dequeue operations. The enqueue operations put the integers 0 through 9 in order onto the queue; the dequeue operations print out the return value. Which of the following sequence(s) could not occur? 0 1 2 3 4 5 6 7 8 9
True
Question 231 / 1 pts The following statement is an example of ________.import java.util.*;
a wildcard import statement
After the header, the body of the method appears inside a set of ________.
braces, {}
One or more objects may be created from a(n) ________.
class
A(n) ________ can be thought of as a blueprint that can be used to create a type of ________.
class, object
Given the following statement, which statement will write the string "Calvin" to the file DiskFile.txt?PrintWriter diskOut = new PrintWriter("DiskFile.txt");
diskOut.println("Calvin");
It is common practice in object-oriented programming to make all of a class's ________
fields private
A class specifies the ________ and ________ that a particular type of object has.
fields, methods
A constructor ________.
has the same name as the class
Overloading means that multiple methods in the same class ________.
have the same name but different parameter lists
When working with the PrintWriter class, which of the following import statements should you have near the top of your program?
import java.io.*;
You should not define a class that is dependent on the values of other class fields ________.
in order to avoid having stale data
Another term for an object of a class is a(n) ________.
instance
Methods that operate on an object's fields are called ________.
instance methods
Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?
int number = inputFile.nextInt();
A reference variable stores a(n) ______
memory address
Instance methods do not have the ________ key word in their headers.
static
Which of the following is not involved in identifying the classes to be used when developing an object-oriented application?
the code
In a queue, a pop operation always removes _____ element.
the front
The scope of a public instance field is ________.
the instance methods and methods outside the class.
The scope of a private instance field is ________
the instance methods of the same class
Two or more methods in a class may have the same name as long as ________.
they have different parameter lists