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.
Identifiers can begin with what characters?
A letter, an underscore, or a currency character.
After the first character, identifiers can also include…?
digits.
How long can identifiers be made?
Any length.
JavaBeans methods must be named using what kind of format?
camelCase
Depending on the method’s purpose, JavaBeans methods must start with what?
set, get, is, add, or remove
A ________ code file can have only one public class.
source
(True/False) If the source file contains a public class, the filename cannot match the public class name.
false (it must match)
A file can have only one _______ statement, but multiple imports.
package
The package statement (if any) must be the ________ (non-comment) line in a source file.
first
The ________ statements (if any) must come after the package and before the class declaration.
import
If there is no package statement, what type of statements must be the first (non-comment) statements in the source file?
import
(True/False) Package and import statements apply to some of the classes in the file?
false (applies to all the classes)
Can a file have more than one nonpublic class?
yes
Do files with no public classes have naming restrictions?
no
What are the three access modifiers?
public, protected, and private
What are the four levels of access?
public, protected, default, and private
Classes can have only public or ______ access.
default
(True/False) A class with default access can be seen only by classes within the same package.
true
A class with ______ _______ can be seen by all classes from all packages.
public access
Class visibility revolves around whether code in one class can ____an instance of another class, _____ another class, and ____methods and variables of another class.
create, extend or subclass, access
Classes can also be modified with ______, abstract, or ________.
final…strictfp
Can a class be both final and abstract?
no
What type of class cannot be subclassed?
final
What type of class cannot be instantiated?
abstract
A single abstract method in a class means the _______ class must be abstract.
whole
An _______ class can have both abstract and nonabstract methods.
abstract
The first ________ class to extend an abstract class must implement all of its abstract methods.
concrete
____________ are contracts for what a class can do, but they say nothing about the way in which the class must do it.
interfaces
Interfaces can be implemented by any class, from any __________ ________.
inheritance tree
Are interfaces like 100-percent abstract class, and are implicitly abstract whether you type the abstract modifier in the declaration or not?
Yes
An interface can have only ________ methods, no ______ methods allowed.
abstract, concrete
Interface methods are by default _________ and ______–explicit declaration of these modifiers is optional.
public, abstract
(True/False) Interfaces can have constants, which are never public, static, or final.
False, they are always public, static, and final
Interface constant declarations of public, static, and final are ________ in any combination.
optional
A class implementing an interface can itself be _______.
abstract
An abstract implementing class does/does not have to implement the interface methods (but the first concrete subclass must.
does not
A class can/cannot extend one class, but it can/cannot implement many interfaces.
can, can