(6-7) Flashcards
(72 cards)
Data hiding, which means 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
The scope of a public instance field is:
the instance methods and methods outside the class
Instance methods do not have the key word static in their headers
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
The java.lang package is automatically imported into all Java programs
True
A method that gets a value from the class’s field but does not change it is known as a mutator method
False
For the following code, which statement is NOT true?
public class Circle
{
private double radius;
private double x;
private double y;
}
Y is available to code that is written outside the Circle class
It is common practice in object-oriented programming to make all of a class’s:
fields private
For the following code which statement is NOT true?
public class Sphere
{
private double radius;
public double x;
private double y;
private double z;
}
Z is available to code that is written outside the circle class
Java allows you create objects of this class in the same way you would create primitive values
String
The public access specifier for a field indicates that the attribute may not be accessed by statements outside the class
False
A class in not an object, but description of an object
True
An object can store data
True
A class specifies _________ and ______ that a particular type of object has
fields; methods
Look at the following statement:
import.java.util.*;
This is an example of:
A wildcard import
A constructor:
has the same name as the class
Which of the following statements will create a reference, str, to the String, “Hello, World”?
String str = “Hello, World”;
Which of the following are classes from the Java API?
Scanner, Random, and PrintWriter
You should not define a class field that is dependent upon the values of other class fields:
in order to avoid having stale data
Methods that operate on an object’s fields are called:
instance methods
Which of the following will create a reference, str, to the string, “Hello, World?”
- String str = new String(“Hello World);
- String str = “Hello, world”;
Both 1 and 2
Class objects normally have __________ that perform useful operations on their data, but primitive values do not.
methods
One or more objects may be created from a(n)
class
What is stored by a reference variable?
A memory address