Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
52 Cards in this Set
- Front
- Back
Given:
class A {} class B {} Define access in terms of class B to class A |
Code from class B can instantiate an object of class A. Class B can extend class A.
|
|
What two access modifiers can be used with class definitions?
|
public
default (no modifier) |
|
Define default access regarding classes
|
Code only accessible to classes in the same package
|
|
Define public access regarding classes
|
Code is accessible to any class in the same package and must be imported to classes in separate packages
|
|
Given:
// A.java package pack1; class A {} // B.java package pack1; class B {}; Name the type of access that exists between these two classes |
Default
|
|
Will the following code segment compile? Why or why not?
//A.java package pk1; class A { } //B.java package pk2; import pk1.A; class B extends A { } |
No. Class has default access only to classes in the same package and class B is in a completely different package.
|
|
Will the following compile? Why or Why not?
//A.java package pk1; public class A { } //B.java package pk2; import pk1.A; class B extends A { } |
Yes. Class A has public access and class B has imported public class A.
|
|
What are 5 characteristics of Abstract classes?
|
1: Can't be instantiated and must be sub-classed
2: abstract methods must be marked public abstract 3: can have fully implemented methods 4: can declare instance variables 5: The first concrete subclass must implement all abstract methods or be marked abstract. |
|
How many abstract methods are required to consider a class abstract?
|
One.
|
|
What are nine characteristics of interfaces?
|
1: a 100% abstract class
2: can only have abstract methods 3: implicitly abstract 4: can extend other interfaces 5: methods are implicitly public abstract 6: all methods must be fully implemented or class should be marked abstract 7: instance variables are implicitly public static final and can't be modified 8: methods can't be static, final, protected, private 9: can be used polymorphically (Interface type) |
|
What does strictfp mean when applied to a class?
public strictfp class A { } |
The class has methods which conform to IEEE 754 standards for floating point operations.
|
|
What is a characteristic of a class marked final?
public final class A { } |
Final classes can't be subclassed.
|
|
Given:
class A {} class B {} Define member access in terms of class B to class A |
Code in class B can instantiate objects of class A. Code in class B can invoke methods on objects of class A. Code in class B can inherit a member of class A.
|
|
Define public member access.
|
Assuming the class is visible via public or default access, all other classes can access this method or variable and methods of this type can be overriden via inheritance.
|
|
Define private member access.
|
Assuming the class is visible, private members can only be accessed in the class where they are declared and are not inherited by the subclasses. private methods cannot be overriden
|
|
Define default member access.
|
members can only be accessed only by a class in the same package.
are not inherited by subclasses in diff packages |
|
Defiine protected member access.
|
members can only be accessed only by a class in the same
package. can be accessed by inherited subclasses in diff packages |
|
When a class's method is marked final, what does that mean?
|
It is a method that can't be overriden
|
|
When a method has an argument marked final, what does that mean?
|
Final method arguments can't be modified.
|
|
What is a synchronized method?
|
A method that can accessed by only 1 thread at a time.
|
|
What is a strictfp method?
|
A a method that conforms to the IEEE 754 standard for floating point operations.
|
|
Write method named m1. Should have with default access, no return type, and a variable argument list of type class A
|
void m1(A... a) {
} |
|
What the three characteristics regarding methods with variable argument lists?
|
The var args must be last parameter in the method.
Can only have one per method signature. Can have other parameters in the method signature. |
|
What are five characteristics of constructors?
|
No return type
Can use access modifiers Can take arguments and var args Must have same name as the class Can't be static, final, or abstract |
|
Name the 7 Java primatives
|
char
boolean byte short int long double float |
|
declare an array of ints
|
int[] variableName;
|
|
What type of variable must be initialized and can't be changed?
|
A final variable
|
|
What is a static variable?
|
One copy for the entire class
|
|
Given
enum TestEnum {ONE, TWO, THREE} class A { TestEnum te; } public class Test1 { public static void main(String[] args) { A a = new A(); a.te = FILL IN THE BLANK; } } |
a.te = TestEnum.ONE;
the enum is defined outside of the class can be referenced with the enum's name |
|
Given
class A { TestEnum te; enum TestEnum {ONE, TWO, THREE}; } public class Test1 { public static void main(String[] args) { A a = new A(); a.te = FILL IN THE BLANK; } } |
a.te = A.TestEnum.ONE;
|
|
What are 4 characteristics of enum's?
|
Can't invoke enum constructor directly
Can't declare enum in a method enum constructor can have none or many values can be declared in their own class or enclosed in another class |
|
What three characters can an identifiers begin with?
|
letter
underscore currency symbol |
|
When can identifier names includes digits?
|
After the first character
|
|
What are the javabeans method naming rules
|
camelCasing
set get is add remove |
|
How many public classes can appear in a single source file?
|
One
|
|
If a source file has a public class, what should the file name be?
|
Same as the public class name.
|
|
How many package statements can a source file have?
|
One
|
|
Where do import statements go?
|
After the package statement if there is one they should be the first no comment in a source file
|
|
How many non public classes can a source file have?
|
one or more
|
|
If a source file has no public class, what should it's filename be?
|
What ever you like.
|
|
What are the three access modifiers?
|
public
protected private |
|
What are the four levels of access?
|
default
public private protected |
|
What type of access can classes have?
|
public or default
|
|
A class with default access can be seen by...
|
only classes in 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 another class Access methods and variables of another class |
|
What are the three non access modifiers that can be used for classes?
|
final
abstract strictfp |
|
Can a class be both final and abstract?
|
No
|
|
Can an abstract class be instantiated?
|
no
|
|
Can an interface have concrete methods?
|
no
|
|
Interface methods have what implicit modifiers?
|
public abstract
|
|
Interface constants have what implicit modifiers?
|
public static final
|