Exam 1 Flashcards

(98 cards)

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
Number variables actually ____________
Store numbers
26
When you copy a number, the original and the copy of the number are _______________
Independent values
27
When you copy an object reference both the original and the copy are references to the _________
Same object
28
Start the comment with a
/**
29
Omit _______ tag for methods that have no arguments
@param
30
Omit the _________ tag for methods whose return type is void
@return
31
End a comment with
*/
32
API
Application programming interface
33
Lists classes and methods of the java library
API documentation
34
A programmer who uses the java classes to put together a computer program (or application)
Application programmer
35
A programmer who designs and implements library classes such as PrintStream and Rectangle
Systems programmer
36
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
Constructor No-argument Argument
37
_______________ store data of an object
Instance variable
38
_____________ is an object of the class
Instance of a class
39
An ____________ is a storage location in each object created from a class
Instance variable
40
The ____________ specifies the instance variables
Class declaration
41
An objects instance variables store the ________ requires for executing its methods
Data
42
An ________________________ consists of the following parts: Access specifier Type of variable Name of variable
Instance variable declaration
43
An instance variable declaration consists of:
``` Access specifier (such as private) Type of variable(such as int) Name of variable(such as value) ```
44
You should declare all instance variables as ____________
Private
45
Each object of a class has __________ of instance variables
It’s own set
46
The ________________: Terminated the method call Returns a result to the methods called
Return statement
47
Affects the value of the ______________ of an object on which the method is invoked
Instance variable
48
___________ instance variables can ______ be accesses by methods of the ______ class
Private Only Same
49
What is encapsulation?
Process of hiding implementation details and providing methods for data access
50
How to encapsulate data?
Declare instance variables as PRIVATE declare PUBLIC methods that access the variable
51
_________ allows a programmer to use a class without having to know its implementation
Encapsulation
52
Information hiding makes it simpler for the implementer of a class to?
Locate errors and change implementations
53
In order to implement a class, you first?
Need to know which methods are required
54
A methods ______ consisting of statements that are executed when the method is called:
Body
55
Public methods can be called by __________ in the entire program
All other methods
56
Private methods can only be called by ____________________
Other methods in the same class
57
Private methods are _____ part of the public interface
Not
58
The name of the constructor is always the _________ as the name of the class
Same
59
Constructors have _____ return type
No
60
The constructor name is ________ the same as the class name
Always
61
A constructor that takes no arguments is called a __________________
No-argument constructor
62
Public constructors and methods of a class form the _____________ of the class
Interface
63
The _________________ of a class consists of: Private instance variables The bodies of constructors The bodies of methods
Private implementation
64
What does the private implementation of a class consist of?
Private instance variable The bodies of constructors The bodies of methods
65
Constructors job is to __________ the instance variables of the object
Initialize
66
What is the memory location of an object?
Object reference
67
_________ update the instance variables in some way
Mutator or setter
68
_______ retrieves or computes a result
Accessor or getter
69
Updates the balance
Deposit method
70
Updates the balance subtracting
Withdraw method
71
An accessor method that returns the balance
getBalance
72
Scope __________ are declared in the body of a method
Local variables
73
Scope __________ are declared in the header of a method
Parameter variables
74
Scope Local and parameter variables belong to _________
Methods
75
Local and parameter in methods exits, they are _______________
Removed immediately
76
Scope Instance variables belong to _________
Objects
77
Instance variables are initialized to a _____________
Default value
78
Default values of Object references are set to a special value called _____
Null
79
Default value for numbers are
0
80
A ______ object reference refers to no object at all
Bull
81
You must _______ local variables
Initialize
82
What happens if you do not initialize local variables
The compiler complains
83
What do local variables and parameter variables have in common?
Belong to methods/ come alive when called Both die the the method exits
84
What aspect do local variables and parameter variables differ
Initialization Parameter variables are initialized with the call value Local variables much be explicitly initialized
85
Two types of imputs are passed when ______ method is called: The OBJECT on which you invoke the method The method argument
This
86
public void deposit(double amount) { balance = balance + amount; } What is the explicit parameter?
amount
87
public void deposit(double amount) { balance = balance + amount; } The _________ parameter (momSavings) is not seen
Implicit
88
When you reference to an instance variable inside a method, it means?
The instance variable of the implicit parameter
89
The this reference denotes the _______________
Implicit parameter
90
When you reference to an instance variable in a method, the compiler automatically applies it to the _____________
this reference
91
A local variable ____________ an instance variable that has the same name
Shadows
92
In java, local and parameter variables are considered _______ when looking up variable names
first
93
A method call without the implicit parameter is applies to the _____________
Same object
94
Why can’t BankAccount.java be executed?
No main method | Most classes do not have a main method
95
BankAccount.java should be tester before using in a larger program in ___________
Isolation
96
Verifies that a class works correctly in isolation, outside a complete program
Unit test
97
A class with a main method that contains statements to test another class
Tester class
98
Tester class typically carries out the following steps
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