Chapter 6 Flashcards
True or False, Constructors create and initialize new objects?
True
True or False, A constructor is a special method that is called when you use the new operator to create a new object
True
Using __ calls a constructor
new
What part is earthSpecies and what part is Species in Species earthSpecies = new Species();
- earthSpecies to be a name for an object
- in class Species.
- The second part, newSpecies(), creates and initializes a new object, whose address is then assigned to earthSpecies.
- Species() is a call to the constructor that Java provided for the class. The parentheses are empty because this particular constructor takes no arguments.
True/False .A constructor supplied by Java uses default initial values
True
True or False, the constructors create objects and give their instance variables default initial values. These values might not be what you want, however. Instead, you may wish to have some or all instance variables initialized to your specifications at the time an object is created. You can do this by writing your own constructors.
True
Constructors serve essentially the same purpose as ___
setters or set methods
True or False, A constructor can perform any action you write into its definition, but a constructor is meant to perform initializing actions, such as initializing the values of instance variables.
True
True or False, When you define a constructor, you do not specify any return type, not even void. These constructors look very much like our set methods, which are void methods.
True
Instance variables that you do not initialize are given ___ initial values by Java
default
True or False, A default constructor has no parameters
True
When you create a new object by using the operator new, you must always include a __ to a constructor.
call
Pet fish = new Pet(“Wanda”, 2, 0.25); , describe this line of code
The part Pet(“Wanda”, 2, 0.25) is a call to the constructor in Pet that takes three arguments:
This statement creates a new object to represent a pet named Wanda who is 2 years old and weighs 0.25 pound.
True of False, You cannot use an existing object to call a constructor
True
True of False, A constructor that calls a public method can cause a problem
True
A constructor and a __ method can call the same private method
set
What is “ this “ called? this(initialName, 0, 0);
Calling a Constructor from Other Constructors
___ variables and ___ methods belong to a class as a whole and not to an individual object.
Static, Static
There are three types of variables
local variables, instance variables, and static (class) variables.
Invoke a __ method using the class name, not an object name
static
True or False, A non-static method can reference a static variable or call a static method
True
True or False ,A static method cannot call a non-static method unless it has an object
True
could a static method reference an instance variable?
no
A static method can call only a __ method
static
True or false, a static method can invoke only static methods and reference only static variables. It cannot invoke a non-static method of the same class unless you have an object of the class to use in the invocation.
True
it makes sense to have a main method within a class definition. The class can then be used for two purposes: It can be used to create objects in other classes, or it can be ____ .
run as a program
What do you call the need to convert the primitive value—such as the int value 42—to an “equivalent” value of some class type that corresponds to the primitive type int?
wrapper class
The constant value___ is a special predefined constant that you can use to give a value to any variable of any class type.
null
What is driver program?
All they have to do is give the method some arguments and invoke the method.
When you give two or more methods the same name within the same class, you are____ the method name.
Overloading
A ____ is a collection of classes
package
A ___ is simply a collection of classes that have been grouped together into a folder. The name of the folder is the name of the _____ .
package, package
You can use all the classes that are in a package within any program or class definition by placing ____ statement that names the package at the start of the file containing the program or class definition.
an import …
syntax: import Package_Name.Class_Name
To import all the classes in the package general.utilities, you would use the following import statement:
import general.utilities.*;
The value of your class __ variable tells Java where to begin its search for a package,
path