Ch. 6 - A First Look at Classes
In UML diagrams, this symbol indicates that a member is public.
+
In UML diagrams, this symbol indicates that a member is private:
-
What is stored by a reference variable?
A memory address
Look at the following statement. import java.util.*; This is an example of:
A wildcard import
Which of the following are classes from the Java API?
All of the above (Scanner, Random, PrintWriter)
Look at the following statement. import java.util.Scanner; This is an example of:
An explicit import
Which of the following statements will create a reference, str, to the string, "Hello, world"? (1) String str = new String("Hello, world"); (2) String str = "Hello, world";
Both 1 & 2
After the header, the body of the method appears inside a set of:
Braces { }
One or more objects may be created from a:
Class
In your textbook the general layout of a UML diagram is a box that is divided into three sections. The top section has the _______; the middle section holds _______; the bottom section holds _______.
Class name; attributes or fields; methods
In the cookie cutter metaphor, think of the ________ as a cookie cutter and ________ as the cookies.
Class; objects
This refers to the combining of data and code into a single object.
Encapsulation
TRUE/FALSE: A method that gets a value from a class's field but does not change it is known as a mutator method.
False
TRUE/FALSE: Instance methods should be declared static.
False
TRUE/FALSE: The public access specifier for a field indicates that the attribute may not be accessed by statements outside the class.
False
TRUE/FALSE: The term "default constructor" is applied to the first constructor written by the author of a class.
False
TRUE/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
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 multiple methods in the same class:
Have the same name, but different parameter lists
Quite often you have to use this statement to make a group of classes available to a program.
Import
You should not define a class field that is dependent upon the values of other class fields:
In order to avoid having stale data
Another term for an object of a class is:
Instance
When an object is created, the attributes associated with the object are called:
Instance fields
Methods that operate on an object's fields are called:
Instance methods
The following package is automatically imported into all Java programs.
Java.lang
Class objects normally have __________ that perform useful operations on their data, but primitive variables do not.
Methods
A UML diagram does not contain:
Object names
Most programming languages that are in use today are:
Object-oriented
This is a group of related classes.
Package
A constructor is a method that:
Performs initialization or setup operations.
When you are working with a ____________, you are using a storage location that holds a piece of data.
Primitive variable
Instance methods do not have this key word in their headers:
Static
Java allows you to create objects of this 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";
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
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
A class's responsibilities include:
The things a class is responsible for doing & for knowing (Both)
In a UML diagram to indicate the data type of a variable, enter:
The variable name followed by a colon and the data type
Two or more methods in a class may have the same name as long as:
They have different parameter lists
What does the following UML diagram entry mean? + setHeight(h : double) : void
This is a public method with a parameter of data type double and does not return a value
TRUE/FALSE: A class is not an object, but a description of an object.
True
TRUE/FALSE: A constructor is a method that is automatically called when an object is created.
True
TRUE/FALSE: 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
TRUE/FALSE: An access specifier indicates how the class may be accessed.
True
TRUE/FALSE: An object can store data.
True
TRUE/FALSE: Instance methods do not have the key word static in their headers.
True
TRUE/FALSE: Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.
True
TRUE/FALSE: The java.lang package is automatically imported into all Java programs.
True
TRUE/FALSE: The term "no-arg constructor" is applied to any constructor that does not accept arguments.
True
Data hiding, which means that critical data stored inside the object is protected from code outside the object, is accomplished in Java by:
Using the private access specifier on the class fields
Which of the following is not involved in finding the classes when developing an object-oriented application?
Writing the code