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
Q

A single abstract method in a class means the _______ class must be abstract.

A

whole

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

An _______ class can have both abstract and nonabstract methods.

A

abstract

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

The first ________ class to extend an abstract class must implement all of its abstract methods.

A

concrete

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

____________ are contracts for what a class can do, but they say nothing about the way in which the class must do it.

A

interfaces

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

Interfaces can be implemented by any class, from any __________ ________.

A

inheritance tree

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

Are interfaces like 100-percent abstract class, and are implicitly abstract whether you type the abstract modifier in the declaration or not?

A

Yes

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

An interface can have only ________ methods, no ______ methods allowed.

A

abstract, concrete

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

Interface methods are by default _________ and ______–explicit declaration of these modifiers is optional.

A

public, abstract

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

(True/False) Interfaces can have constants, which are never public, static, or final.

A

False, they are always public, static, and final

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

Interface constant declarations of public, static, and final are ________ in any combination.

A

optional

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

A class implementing an interface can itself be _______.

A

abstract

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

An abstract implementing class does/does not have to implement the interface methods (but the first concrete subclass must.

A

does not

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

A class can/cannot extend one class, but it can/cannot implement many interfaces.

A

can, can

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

Can interfaces extend one or more other interfaces?

A

yes

40
Q

(True/False) Interfaces cannot extend a class, or implement a class or interface.

A

true

41
Q

Methods and instance (nonlocal) variables are known as ________?

A

members

42
Q

Members can use all four access levels. What are those levels?

A

public, protected, default, and private

43
Q

What are the two forms of member access?

A

Code in one class can access a member of another class.

A subclass can inherit a member of its superclass.

44
Q

(True/False) If a class cannot be accessed, its members can be accessed.

A

false, its members cannot have access if the class cannot be accessed

45
Q

What should you determine before determining member visibility?

A

class visibility

46
Q

________ members can be accessed by all other classes, even in other packages.

A

public

47
Q

If a superclass member is public, the subclass does/does not inherit it–regardless of package.

A

does

48
Q

Members accessed without the ________ operator must belong to the same class.

A

Dot

49
Q

“this.” always refers to the ___________ executing object.

A

currently

50
Q

this.aMethod () is the same as just invoking ___________.

A

aMethod ()

51
Q

(True/False) Private member cannot be accessed by code in the same class.

A

false, private members can be accessed only by code in the same class

52
Q

Private members are not visible to subclasses, so private members cannot be ________.

A

inherited

53
Q

Default and protected members differ only when ________ are involved.

A

subclasses

54
Q

(True/False) Default members can be access only by classes in the same package.

A

true

55
Q

________ members can be accessed by all other classes in the same package, plus subclasses regardless of package.

A

protected

56
Q

protected = ________ plus kids (kids meaning subclasses)

A

package

57
Q

Local (method, automatic, or stack) variable declarations cannot have ______ modifiers.

A

access

58
Q

________ is the only modifier available to local variables.

A

final

59
Q

Local variables don’t get default values, so they must be ______ before use.

A

initialized

60
Q

(True/False) Final methods can be overridden in a subclass.

A

false, they cannot be overridden in a subclass

61
Q

Abstract methods are declared, with a signature, a return type, and an optional throws clause, but are not ______.

A

implemented

62
Q

Abstract methods end in a _________–no curly braces.

A

semicolon

63
Q

Name the three ways to spot a non-abstract method.

A

(1) The method is not marked abstract
(2) The method has curly braces
(3) The method has code between the curly braces

64
Q

The first nonabstract (concrete) class to extend an ____________ class must implement all of the _______ class’ __________ methods.

A

abstract, abstract, abstract

65
Q

The __________ modifier applies only to methods and code blocks.

A

synchronized

66
Q

Synchronized methods can have access control and can also be marked ________.

A

final

67
Q

Abstract methods must be implemented by a subclass, so they must be inheritable. For that reason: (Name both reasons)

A

(1) abstract methods cannot be private

(2) abstract methods cannot be final

68
Q

The ________ modifier applies only to methods.

A

native

69
Q

The ________ modifier applies only to classes and methods.

A

strictfp

70
Q

As of Java 5, methods can declare a ____________ that accepts from zero to many arguments.

A

parameter

71
Q

A _________ parameter is declared with the syntax type…name; for instance: doStuff (int…x) { }

A

var-arg

72
Q

A var-arg method can have only one var-gar _______.

A

parameter

73
Q

(True/False) In methods with normal parameters and a var-arg, the var-arg must come last.

A

true

74
Q

Instance variable can…

A

(1) Have any access control (2) Be marked final or transient

75
Q

Instance variables can’t be __________, _____________, _____________, or __________.

A

abstract, synchronized, native, strictfp

76
Q

Is it legal to declare a local variable with the same name as an instance variable (also called “shadowing”)?

A

yes

77
Q

What are the three properties of final variables?

A

(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
Q

(True/False) There is no such thing as a final object.

A

true–an object reference marked final does not mean the object itself is immutable

79
Q

The transient modifier applies only to _________ variables.

A

instance

80
Q

The volatile __________ applies only to instance variables.

A

modifier

81
Q

_________ can hold primitives or objects, but the array itself is always object.

A

arrays

82
Q

When you _______ an array, the brackets can be to the left or right of the variable name.

A

declare

83
Q

(True/False) It is always legal to include the size of an array in the declaration.

A

false–it is never legal to include the size of an array in the declaration

84
Q

An array of object can hold any object that passes the ______ ______ for the declared type of the array.

A

IS-A test

85
Q

Static variables and methods are/are not tied to any particular instance of a class.

A

are not

86
Q

No classes instances are needed in order to use ________ members of the class

A

static

87
Q

________ methods do not have a direct access to non-static members

A

static

88
Q

An ______ specifies a list of constant values assigned to a type

A

enum

89
Q

An enum is/is not a String or an int.

A

is not

90
Q

An enum can be declared outside or inside a class, but not in a ___________.

A

method

91
Q

An enum declared outside a class must not be marked _______, _______, _______, _______, or _______.

A

final, abstract, static, protected, private

92
Q

Enums can contact constructors, methods, _______, and constant class bodies.

A

variables

93
Q

Enum contacts can send ___________ to the enum constructor, using the syntax BIG(8), where the in literal 8 is passed to the enum constructor

A

arguments

94
Q

(True/False) Enum constructors can never be invoke directly in code.

A

true

95
Q

MyEnum.values () returns….

A

an array of MyEnum’s values