Variables, Objects, and Classes Flashcards

(46 cards)

1
Q

The goal of object technology is to allow you to write software that better models the natural world. (T/F)

A

True

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

A unit within a computer program that combines data and operations

A

Object

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

Variables internal to an object that hold data defining the object’s state

A

Instance variable

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

An operation that an object can perform

A

Method

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

A plan that tells the computer how to build objects

A

Class

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

Specifies the variables that are to be included in objects of the class

A

Field declaration

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

Specifies the methods that are to be included in objects of the class

A

Method declaration

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

A special method that, when called, initializes the object being built

A

Constructor

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

A constructor that is automatically provided by the compiler

A

Implicit constructor

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

A constructor that is written out within the text of the class

A

Explicit constructor

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

Specified by a static field declaration, a variable shared by all objects of a class

A

Class variable

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

Specified by a static method declaraion, a method shared by all objects of a class

A

Class method

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

Indicates that a field or method belongs to the entire class and not to individual objects of the class

A

Static

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

Object-oriented programmers refer to an object as __________ of a class.

A

An instance

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

You can always identify an explicit constructor within a class declaration because it has the same identifier as the class. (T/F)

A

True

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

Given this Die class, which is its field?

public class Die {
     public int faceUp;
     public void roll( ) {
          faceUp = (int) (Math.random( ) * 6 + 1); 
}}
A

faceUp

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

Given this Die class, which is its method?

public class Die {
     public int faceUp;
     public void roll( ) {
          faceUp = (int) (Math.random( ) * 6 + 1); 
}}
A

roll( )

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

Given this Die class, does it have an implicit or explicit constructor?

public class Die {
     public int faceUp;
     public void roll( ) {
          faceUp = (int) (Math.random( ) * 6 + 1); 
}}
A

Implicit

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

Given this Die class, does it have an implicit or explicit constructor?

public class Die {
     public int faceUp;
     public Die ( ) {
          roll( );
     }
     public void roll( ) {
          faceUp = (int) (Math.random( ) * 6 + 1);
}}
20
Q

If a class has no constructor explicitly written out, the Java compiler automatically gives it an implicit constructor. (T/F)

21
Q

A __________ has as its declared data type one of the eight data types (e.g. int, double, char, etc.) that are built into the Java language.

A

Primitive variable

22
Q

A __________ has as its declared data type a Java class.

A

Reference variable

23
Q

A __________ is a direct reference to its datum.

A

Primitive variable

24
Q

A __________ is an indirect reference to its data.

A

Reference variable

25
__________ stores its datum immediately within the memory location.
A direct reference
26
__________ stores an address that the computer must travel to in order to find the data.
An indirect reference
27
__________ variable holds a whole number.
An integer
28
__________ variable holds a number with a fractional part.
A floating-point
29
What code fragment declares s to be a reference variable?
String s;
30
What code fragment declares s to be a primitive variable?
double s;
31
Java objects can only be accessed through an associated reference variable. (T/F)
True
32
A reference variable that doesn't refer to any object is called a null pointer. (T/F)
True
33
Given this Die class, what Java statement correctly builds a Die object? ``` public class Die { public int faceUp; public Die ( ) { roll( ); } public void roll( ) { faceUp = (int) (Math.random( ) * 6 + 1); }} ```
Die d = new Die ( );
34
Which part of the code below declares the object's reference variable? Scanner in = new Scanner( System.in );
Scanner in
35
Which part of the code below calls the class constructor to initialize the object? Scanner in = new Scanner( System.in );
Scanner( System.in );
36
Which part of the code below builds the object? Scanner in = new Scanner( System.in );
new Scanner
37
Which part of the code below copys the address where the object is located in memory to the reference variable? Scanner in = new Scanner( System.in );
in = new
38
Given this HourlyWorker class, which code fragment correctly references Sam's hoursWorked? ``` public class HourlyWorker { public static double hourlyWage; public double hoursWorked; public static void setWage( double w ) { hourlyWage = w; } public void setHours( double h) { hoursWorked = h; } public double grossPay( ) { return hoursWorked * hourlyWage; }} ```
``` HourlyWorker sam = new HourlyWorker( ); sam.hoursWorked = 40.0; ```
39
Given this HourlyWorker class, which code fragment correctly references Sam's hourlyWage? ``` public class HourlyWorker { public static double hourlyWage; public double hoursWorked; public static void setWage( double w ) { hourlyWage = w; } public void setHours( double h) { hoursWorked = h; } public double grossPay( ) { return hoursWorked * hourlyWage; }} ```
``` HourlyWorker sam = new HourlyWorker( ); sam.hourlyWage = 12.25; -or- HourlyWorker sam = new HourlyWorker( ); HourlyWorker.hourlyWage = 12.25; ``` Although the second option is the best
40
Given this HourlyWorker class, which code fragment correctly calls setWage? ``` public class HourlyWorker { public static double hourlyWage; public double hoursWorked; public static void setWage( double w ) { hourlyWage = w; } public void setHours( double h) { hoursWorked = h; } public double grossPay( ) { return hoursWorked * hourlyWage; }} ```
``` HourlyWorker sam = new HourlyWorker( ); sam.setWage( 12.25 ); -or- HourlyWorker sam = new HourlyWorker( ); HourlyWorker.setWage( 12.25 ); ``` Although the second option is best
41
Given this HourlyWorker class, which code fragment correctly calls setHours? ``` public class HourlyWorker { public static double hourlyWage; public double hoursWorked; public static void setWage( double w ) { hourlyWage = w; } public void setHours( double h) { hoursWorked = h; } public double grossPay( ) { return hoursWorked * hourlyWage; }} ```
``` HourlyWorker sam = new HourlyWorker( ); sam.setHours( 40.0 ); ```
42
Given this HourlyWorker class, which code fragment correctly calls grossPay? ``` public class HourlyWorker { public static double hourlyWage; public double hoursWorked; public static void setWage( double w ) { hourlyWage = w; } public void setHours( double h) { hoursWorked = h; } public double grossPay( ) { return hoursWorked * hourlyWage; }} ```
``` HourlyWorker sam = new HourlyWorker( ); . . . double pay = sam.grossPay( 40.0 ); ```
43
The easiest way to compile and run a Java program using more than one class is to have all necessary class files contained in the same disk folder. (T/F)
True
44
An external reference is the occurrence in some file A of an identifier x that is declared in another file B. (T/F)
True
45
To resolve an external reference, the Java compiler automatically searches for its declaration, a process called separate compilation. (T/F)
True
46
Each Java class is compiled into a separate file that has __________ as its extension.
.class