COSC-2403 Exam #2
________ refers to combining data and code into a single object.
Encapsulation
A method that gets a value from a class's field but does not change it is known as a mutator method.
False
Instance methods should be declared static.
False
The term "default constructor" is applied to the first constructor written by the author of the class.
False
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
False
When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.
False
Select all that apply. Which of the following are classes from the Java API?
Scanner Random PrintWriter
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";
For the following code, which statement is not true? public class Circle { private double radius; public double x; private double y; }
The y field is available to code written outside the Circle class.
For the following code, which statement is not true? public class Circle { private double radius; public double x; private double y; private double z; }
The z field is available to code written outside the Sphere class.
A class is not an object. It is a description of an object.
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
Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.
True
The java.lang package is automatically imported into all Java programs.
True
When an object is passed as an argument to a method, the object's address is passed into the method's parameter variable.
True
What does the following UML diagram entry mean? + setHeight(h : double) : void
a public method with a parameter of data type double that does not return a value
A class's responsibilities include ________. a) the things a class is responsible for knowing b) the things a class is responsible for doing c) both of these d) neither of these
c) both of these
Data hiding (which means that critical data stored inside the object is protected from code outside the object) is accomplished in Java by ________. a) using the public access specifier on the class methods b) using the private access specifier on the class methods Correct: c) using the private access specifier on the class fields d) using the private access specifier on the class definition
c) using the private access specifier on the class fields
A(n) ________ can be thought of as a blueprint that can be used to create a type of ________.
class, object
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
You should not define a class that is dependent on the values of other class fields ________.
in order to avoid having stale data
The ________ package is automatically imported into all Java programs.
java.lang
A reference variable stores a(n) ________.
memory address
Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.
methods
A group of related classes is called a(n) ________.
package
A constructor is a method that ________.
performs initialization or setup operations
Instance methods do not have the ________ keyword in their headers.
static
The scope of a public instance field is ________.
the instance methods and methods outside the class
A UML diagram does not contain ________.
the object names
When an object is passed as an argument to a method, what is passed into the method's parameter variable?
the object's memory address
Two or more methods in a class may have the same name as long as ________.
they have different parameter lists