Chapter 6 Flashcards

1
Q

True or False, Constructors create and initialize new objects?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False, A constructor is a special method that is called when you use the new operator to create a new object

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Using __ calls a constructor

A

new

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
What part is earthSpecies and what part is Species  in 
Species earthSpecies = new Species();
A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

True/False .A constructor supplied by Java uses default initial values

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Constructors serve essentially the same purpose as ___

A

setters or set methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Instance variables that you do not initialize are given ___ initial values by Java

A

default

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

True or False, A default constructor has no parameters

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

When you create a new object by using the operator new, you must always include a __ to a constructor.

A

call

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Pet fish = new Pet(“Wanda”, 2, 0.25); , describe this line of code

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True of False, You cannot use an existing object to call a constructor

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

True of False, A constructor that calls a public method can cause a problem

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A constructor and a __ method can call the same private method

A

set

17
Q

What is “ this “ called? this(initialName, 0, 0);

A

Calling a Constructor from Other Constructors

18
Q

___ variables and ___ methods belong to a class as a whole and not to an individual object.

A

Static, Static

19
Q

There are three types of variables

A

local variables, instance variables, and static (class) variables.

20
Q

Invoke a __ method using the class name, not an object name

A

static

21
Q

True or False, A non-static method can reference a static variable or call a static method

A

True

22
Q

True or False ,A static method cannot call a non-static method unless it has an object

A

True

23
Q

could a static method reference an instance variable?

A

no

24
Q

A static method can call only a __ method

A

static

25
Q

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.

A

True

26
Q

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 ____ .

A

run as a program

27
Q

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?

A

wrapper class

28
Q

The constant value___ is a special predefined constant that you can use to give a value to any variable of any class type.

A

null

29
Q

What is driver program?

A

All they have to do is give the method some arguments and invoke the method.

30
Q

When you give two or more methods the same name within the same class, you are____ the method name.

A

Overloading

31
Q

A ____ is a collection of classes

A

package

32
Q

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 _____ .

A

package, package

33
Q

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.

A

an import …

syntax: import Package_Name.Class_Name

34
Q

To import all the classes in the package general.utilities, you would use the following import statement:

A

import general.utilities.*;

35
Q

The value of your class __ variable tells Java where to begin its search for a package,

A

path