1.Declarations and Access Control Flashcards
Identifiers can begin with…
a letter, an underscore, or a currency character
After the first character…
identifiers can also include digits
Identifier length can be…
Identifiers can be of any length
You can compile and execute Java programs using the command-line programs…
java and javac. Both programs support a variety of
command-line options.
The only versions of main() methods with special powers are those
versions with method signatures equivalent to…
public static void main(String[] args)
can main be overloaded?
Yes
what does an import statement is good for?
only job is to save keystrokes
why do we use asterisk (*) in imports?
to search through the contents of a single
package
what is the syntax for static imports?
import static….
how many public classes can a source file have?
only one
If the source file contains a public class, what can be the class names?
the filename must match the public class name
How many package statements can a file have?
Only one
Where is the correct place for package statement
the first line in a source file
Where is the correct place for import statement
after the package and before the class declaration. If there is no package statement, import statements must be the first (noncomment) statements in the source file.
how the package and import statements apply to classes in a file
to all classes in the file
how many nonpublic classes can a file have?
more than one
How can we name nonpublic classes?
no public classes have no naming restrictions
What are class access modifiers?
public, protected, and private
How many access levels are there?
public, protected, default, and private
Which accesses a class can have?
public or default access
A class with default access can be seen..
only by classes within the same
package.
A class with public access can be seen by…
all classes from all packages.
Class visibility revolves around whether code in one class can…
❑ Create an instance of another class
❑ Extend (or subclass) another class
❑ Access methods and variables of another class
Nonaccess modifiers for classes are…
final, abstract, or strictfp
Can a class be both final and abstract?
No
What does it mean for a class to have “final” as modifier?
A final class cannot be subclassed.
What does it mean for a class to have “abstract” as modifier?
An abstract class cannot be instantiated
Can a non abstract class have an abstract method inside?
No. A single abstract method in a class means the whole class must be abstract.
Can an abstract class have non abstract methods?
Yes, an abstract class can have both abstract and nonabstract methods.
When should the abstract methods be implemented?
The first concrete class to extend an abstract class must implement all of its abstract methods
What is an interface?
Interfaces are contracts for what a class can do, but they say nothing about the way in which the class must do it.
What is the rule for implementing an interface in means of hierarchy tree?
Interfaces can be implemented by any class, from any inheritance tree