Declarations and Access Control Flashcards

* Declare Classes & Interfaces. * Develop Interfaces & Abstract Classes. * Use Primitives, Arrays, Enums, & Legal Identifiers. * Use Static Methods, JavaBeans Naming and Var-Args.

2
Q

Identifiers can begin with what characters?

A

A letter, an underscore, or a currency character.

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

After the first character, identifiers can also include…?

A

digits.

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

How long can identifiers be made?

A

Any length.

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

JavaBeans methods must be named using what kind of format?

A

camelCase

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

Depending on the method’s purpose, JavaBeans methods must start with what?

A

set, get, is, add, or remove

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

A ________ code file can have only one public class.

A

source

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

(True/False) If the source file contains a public class, the filename cannot match the public class name.

A

false (it must match)

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

A file can have only one _______ statement, but multiple imports.

A

package

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

The package statement (if any) must be the ________ (non-comment) line in a source file.

A

first

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

The ________ statements (if any) must come after the package and before the class declaration.

A

import

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

If there is no package statement, what type of statements must be the first (non-comment) statements in the source file?

A

import

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

(True/False) Package and import statements apply to some of the classes in the file?

A

false (applies to all the classes)

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

Can a file have more than one nonpublic class?

A

yes

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

Do files with no public classes have naming restrictions?

A

no

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

What are the three access modifiers?

A

public, protected, and private

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

What are the four levels of access?

A

public, protected, default, and private

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

Classes can have only public or ______ access.

A

default

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

(True/False) A class with default access can be seen only by classes within the same package.

A

true

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

A class with ______ _______ can be seen by all classes from all packages.

A

public access

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

Class visibility revolves around whether code in one class can ____an instance of another class, _____ another class, and ____methods and variables of another class.

A

create, extend or subclass, access

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

Classes can also be modified with ______, abstract, or ________.

A

final…strictfp

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

Can a class be both final and abstract?

A

no

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

What type of class cannot be subclassed?

A

final

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

What type of class cannot be instantiated?

A

abstract

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
A single abstract method in a class means the _______ class must be abstract.
whole
27
An _______ class can have both abstract and nonabstract methods.
abstract
28
The first ________ class to extend an abstract class must implement all of its abstract methods.
concrete
29
____________ are contracts for what a class can do, but they say nothing about the way in which the class must do it.
interfaces
30
Interfaces can be implemented by any class, from any __________ ________.
inheritance tree
31
Are interfaces like 100-percent abstract class, and are implicitly abstract whether you type the abstract modifier in the declaration or not?
Yes
32
An interface can have only ________ methods, no ______ methods allowed.
abstract, concrete
33
Interface methods are by default _________ and ______--explicit declaration of these modifiers is optional.
public, abstract
34
(True/False) Interfaces can have constants, which are never public, static, or final.
False, they are always public, static, and final
35
Interface constant declarations of public, static, and final are ________ in any combination.
optional
36
A class implementing an interface can itself be _______.
abstract
37
An abstract implementing class does/does not have to implement the interface methods (but the first concrete subclass must.
does not
38
A class can/cannot extend one class, but it can/cannot implement many interfaces.
can, can
39
Can interfaces extend one or more other interfaces?
yes
40
(True/False) Interfaces cannot extend a class, or implement a class or interface.
true
41
Methods and instance (nonlocal) variables are known as ________?
members
42
Members can use all four access levels. What are those levels?
public, protected, default, and private
43
What are the two forms of member access?
Code in one class can access a member of another class. A subclass can inherit a member of its superclass.
44
(True/False) If a class cannot be accessed, its members can be accessed.
false, its members cannot have access if the class cannot be accessed
45
What should you determine before determining member visibility?
class visibility
46
________ members can be accessed by all other classes, even in other packages.
public
47
If a superclass member is public, the subclass does/does not inherit it--regardless of package.
does
48
Members accessed without the ________ operator must belong to the same class.
Dot
49
"this." always refers to the ___________ executing object.
currently
50
this.aMethod () is the same as just invoking ___________.
aMethod ()
51
(True/False) Private member cannot be accessed by code in the same class.
false, private members can be accessed only by code in the same class
52
Private members are not visible to subclasses, so private members cannot be ________.
inherited
53
Default and protected members differ only when ________ are involved.
subclasses
54
(True/False) Default members can be access only by classes in the same package.
true
55
________ members can be accessed by all other classes in the same package, plus subclasses regardless of package.
protected
56
protected = ________ plus kids (kids meaning subclasses)
package
57
Local (method, automatic, or stack) variable declarations cannot have ______ modifiers.
access
58
________ is the only modifier available to local variables.
final
59
Local variables don't get default values, so they must be ______ before use.
initialized
60
(True/False) Final methods can be overridden in a subclass.
false, they cannot be overridden in a subclass
61
Abstract methods are declared, with a signature, a return type, and an optional throws clause, but are not ______.
implemented
62
Abstract methods end in a _________--no curly braces.
semicolon
63
Name the three ways to spot a non-abstract method.
(1) The method is not marked abstract (2) The method has curly braces (3) The method has code between the curly braces
64
The first nonabstract (concrete) class to extend an ____________ class must implement all of the _______ class' __________ methods.
abstract, abstract, abstract
65
The __________ modifier applies only to methods and code blocks.
synchronized
66
Synchronized methods can have access control and can also be marked ________.
final
67
Abstract methods must be implemented by a subclass, so they must be inheritable. For that reason: (Name both reasons)
(1) abstract methods cannot be private | (2) abstract methods cannot be final
68
The ________ modifier applies only to methods.
native
69
The ________ modifier applies only to classes and methods.
strictfp
70
As of Java 5, methods can declare a ____________ that accepts from zero to many arguments.
parameter
71
A _________ parameter is declared with the syntax type...name; for instance: doStuff (int...x) { }
var-arg
72
A var-arg method can have only one var-gar _______.
parameter
73
(True/False) In methods with normal parameters and a var-arg, the var-arg must come last.
true
74
Instance variable can...
(1) Have any access control (2) Be marked final or transient
75
Instance variables can't be __________, _____________, _____________, or __________.
abstract, synchronized, native, strictfp
76
Is it legal to declare a local variable with the same name as an instance variable (also called "shadowing")?
yes
77
What are the three properties of final variables?
(1) final variables cannot be reinitialized once assigned a value (2) final reference variables cannot refer to a different object once the object has been assigned to the final variable (3) final reference variables must be initialized before the constructor completes
78
(True/False) There is no such thing as a final object.
true--an object reference marked final does not mean the object itself is immutable
79
The transient modifier applies only to _________ variables.
instance
80
The volatile __________ applies only to instance variables.
modifier
81
_________ can hold primitives or objects, but the array itself is always object.
arrays
82
When you _______ an array, the brackets can be to the left or right of the variable name.
declare
83
(True/False) It is always legal to include the size of an array in the declaration.
false--it is never legal to include the size of an array in the declaration
84
An array of object can hold any object that passes the ______ ______ for the declared type of the array.
IS-A test
85
Static variables and methods are/are not tied to any particular instance of a class.
are not
86
No classes instances are needed in order to use ________ members of the class
static
87
________ methods do not have a direct access to non-static members
static
88
An ______ specifies a list of constant values assigned to a type
enum
89
An enum is/is not a String or an int.
is not
90
An enum can be declared outside or inside a class, but not in a ___________.
method
91
An enum declared outside a class must not be marked _______, _______, _______, _______, or _______.
final, abstract, static, protected, private
92
Enums can contact constructors, methods, _______, and constant class bodies.
variables
93
Enum contacts can send ___________ to the enum constructor, using the syntax BIG(8), where the in literal 8 is passed to the enum constructor
arguments
94
(True/False) Enum constructors can never be invoke directly in code.
true
95
MyEnum.values () returns....
an array of MyEnum's values