Exam 1 Flashcards

1
Q

public class HelloPrinter

What is the access specifier

A

public

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

public class HelloPrinter

What is the class keyword

A

class

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

public class HelloPrinter

What is the class name

A

HelloPrinter

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

What is the code to create a main Method

A

public static void main(String[] args)
{

}

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

public static void main(String[] args)
{

}

What is the access specifier

A

public

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

public static void main(String[] args)
{

}

What is the return type

A

void

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

public static void main(String[] args)
{

}

What is the method name

A

main

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

public static void main(String[] args)
{

}

What is the parameter

A

(String[] args)

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

Scanner class can be used for input from the ___________

A

Keyboard

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

What’s the code to import a scanner class

A

import java.util.Scanner;

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

Code to declare a scanner object

A

Scanner scan = new Scanner(System.in);

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

Name the scanner methods

A

nextLine()
nextInt()
nextDouble()

No nextbooleans or nextchar

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

A class describes a set of objects with the _______ behavior

A

Same

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

Which of the following are legal identifiers?

Greeting1
g
void
101dalmations
Hello, World
A

Only the first two

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

What is the output:

String greeting = “Hello, World!”;
System.out.println(greeting.length());

A

13

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

________ method replaces ALL instances of a substring in a string with a new substring

A

replace

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

What is the output

String river = “Mississippi”;

river = river.replace(“issipp”, “our”);

System.out.println(river);

A

Missouri

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

String river = “Mississippi”;

Is it legal to call river.println(); ? Why or why not?

A

Not legal. Variable river has type string.

println method is not a method of the String class

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

What are the steps in writing a tester class

A
  1. Provide a tester class
  2. Supply a main method
  3. Inside the main method, construct one or more objects.
  4. Apply methods to the objects.
  5. Display the results of the methods calls.
  6. Display the values that you expect to get.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

An ________________ is a variable whose data type is a class.

A

Object variable

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

An object variable does _____ actually hold and object.

A

Not

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

An object variation holds the ___________ of an object

A

Memory location

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

Multiple object variables can refer to the ________ object

A

Same

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

Numbers are _____ objects

A

Not

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

Number variables actually ____________

A

Store numbers

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

When you copy a number, the original and the copy of the number are _______________

A

Independent values

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

When you copy an object reference both the original and the copy are references to the _________

A

Same object

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

Start the comment with a

A

/**

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

Omit _______ tag for methods that have no arguments

A

@param

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

Omit the _________ tag for methods whose return type is void

A

@return

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

End a comment with

A

*/

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

API

A

Application programming interface

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

Lists classes and methods of the java library

A

API documentation

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

A programmer who uses the java classes to put together a computer program (or application)

A

Application programmer

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

A programmer who designs and implements library classes such as PrintStream and Rectangle

A

Systems programmer

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

Once you create your own _________, you can no longer use Java’s default constructor

This is true whether you create a ___________ constructor, and _________ constructor, both types, of more than 2 constructors

A

Constructor

No-argument
Argument

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

_______________ store data of an object

A

Instance variable

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

_____________ is an object of the class

A

Instance of a class

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

An ____________ is a storage location in each object created from a class

A

Instance variable

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

The ____________ specifies the instance variables

A

Class declaration

41
Q

An objects instance variables store the ________ requires for executing its methods

A

Data

42
Q

An ________________________ consists of the following parts:

Access specifier
Type of variable
Name of variable

A

Instance variable declaration

43
Q

An instance variable declaration consists of:

A
Access specifier (such as private)
Type of variable(such as int)
Name of variable(such as value)
44
Q

You should declare all instance variables as ____________

A

Private

45
Q

Each object of a class has __________ of instance variables

A

It’s own set

46
Q

The ________________:

Terminated the method call
Returns a result to the methods called

A

Return statement

47
Q

Affects the value of the ______________ of an object on which the method is invoked

A

Instance variable

48
Q

___________ instance variables can ______ be accesses by methods of the ______ class

A

Private
Only
Same

49
Q

What is encapsulation?

A

Process of hiding implementation details and providing methods for data access

50
Q

How to encapsulate data?

A

Declare instance variables as PRIVATE

declare PUBLIC methods that access the variable

51
Q

_________ allows a programmer to use a class without having to know its implementation

A

Encapsulation

52
Q

Information hiding makes it simpler for the implementer of a class to?

A

Locate errors and change implementations

53
Q

In order to implement a class, you first?

A

Need to know which methods are required

54
Q

A methods ______ consisting of statements that are executed when the method is called:

A

Body

55
Q

Public methods can be called by __________ in the entire program

A

All other methods

56
Q

Private methods can only be called by ____________________

A

Other methods in the same class

57
Q

Private methods are _____ part of the public interface

A

Not

58
Q

The name of the constructor is always the _________ as the name of the class

A

Same

59
Q

Constructors have _____ return type

A

No

60
Q

The constructor name is ________ the same as the class name

A

Always

61
Q

A constructor that takes no arguments is called a __________________

A

No-argument constructor

62
Q

Public constructors and methods of a class form the _____________ of the class

A

Interface

63
Q

The _________________ of a class consists of:

Private instance variables
The bodies of constructors
The bodies of methods

A

Private implementation

64
Q

What does the private implementation of a class consist of?

A

Private instance variable
The bodies of constructors
The bodies of methods

65
Q

Constructors job is to __________ the instance variables of the object

A

Initialize

66
Q

What is the memory location of an object?

A

Object reference

67
Q

_________ update the instance variables in some way

A

Mutator or setter

68
Q

_______ retrieves or computes a result

A

Accessor or getter

69
Q

Updates the balance

A

Deposit method

70
Q

Updates the balance subtracting

A

Withdraw method

71
Q

An accessor method that returns the balance

A

getBalance

72
Q

Scope __________ are declared in the body of a method

A

Local variables

73
Q

Scope __________ are declared in the header of a method

A

Parameter variables

74
Q

Scope Local and parameter variables belong to _________

A

Methods

75
Q

Local and parameter in methods exits, they are _______________

A

Removed immediately

76
Q

Scope Instance variables belong to _________

A

Objects

77
Q

Instance variables are initialized to a _____________

A

Default value

78
Q

Default values of Object references are set to a special value called _____

A

Null

79
Q

Default value for numbers are

A

0

80
Q

A ______ object reference refers to no object at all

A

Bull

81
Q

You must _______ local variables

A

Initialize

82
Q

What happens if you do not initialize local variables

A

The compiler complains

83
Q

What do local variables and parameter variables have in common?

A

Belong to methods/ come alive when called

Both die the the method exits

84
Q

What aspect do local variables and parameter variables differ

A

Initialization

Parameter variables are initialized with the call value

Local variables much be explicitly initialized

85
Q

Two types of imputs are passed when ______ method is called:

The OBJECT on which you invoke the method

The method argument

A

This

86
Q

public void deposit(double amount)
{
balance = balance + amount;
}

What is the explicit parameter?

A

amount

87
Q

public void deposit(double amount)
{
balance = balance + amount;
}

The _________ parameter (momSavings) is not seen

A

Implicit

88
Q

When you reference to an instance variable inside a method, it means?

A

The instance variable of the implicit parameter

89
Q

The this reference denotes the _______________

A

Implicit parameter

90
Q

When you reference to an instance variable in a method, the compiler automatically applies it to the _____________

A

this reference

91
Q

A local variable ____________ an instance variable that has the same name

A

Shadows

92
Q

In java, local and parameter variables are considered _______ when looking up variable names

A

first

93
Q

A method call without the implicit parameter is applies to the _____________

A

Same object

94
Q

Why can’t BankAccount.java be executed?

A

No main method

Most classes do not have a main method

95
Q

BankAccount.java should be tester before using in a larger program in ___________

A

Isolation

96
Q

Verifies that a class works correctly in isolation, outside a complete program

A

Unit test

97
Q

A class with a main method that contains statements to test another class

A

Tester class

98
Q

Tester class typically carries out the following steps

A
  1. Constructs object(s) that is being tested
  2. Income one or more methods
  3. Print out one or more results
  4. Print the expected results