• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/68

Click to flip

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;

68 Cards in this Set

  • Front
  • Back
  • 3rd side (hint)
Class modifiers (access and nonaccess)
-public, default
-final, abstract, strictfp
What does class access mean when the class access modifier is not stated?
Default Access
When would you consider using the modifier 'final' on a class?
methods in that class will ever be overridden
What is the purpose of the non-access modifier 'abstract' for a class?
Abstract Classes An abstract class can never be instantiated. Its sole purpose, mission in life is to be extended (subclassed).
Note, however, that you can compile and execute an abstract class, as long as you don't try to make an instance of it.
What non-access modifier is required of a class that has a abstract method?
if even a single method is abstract, the whole class must be declared abstract.
When can a class be marked with the non-access modifiers 'final' and 'abstract' ?
you can't mark a class or a method as both abstract and final. They have nearly opposite meanings. An abstract class must be subclassed, whereas a final class must not be subclassed.
The code will not compile.
What is the difference between an abstract class and an interface?
Abstract class may have at least one abstract method. An interface has nothing but abstract methods. An interface will not have method implementations .
What modifiers can be declared in a variable in an interface?
public static final (constants)
What modifiers can be used for interface methods?
public, abstract
What two access modifiers can be used with an interface?
public access and default access (package)
When can the value of a constant declared in an interface be changed?
You can't change the value of a constant! Once the value has been assigned, the value can never be modified.
This is due to the use of the 'final' non-access modifier.
What are considered class members?
instance variables and methods
What access-levels can be used for a method?
Whereas a class can use just two of the four access control levels (default or public), members can use all four: public protected default private
What is the difference between the default access control and protected access control?
Default protection is what you get when you don't type an access modifier in the member declaration. The default and protected access control types have almost identical behavior, except for one difference:
What are the three ways to access a method?
1. Put the method in the same class.
2. Invoke the method using a reference to the class the method is in.
3. Invoke an inherited method.
Can a subclass override a superclass member that is marked private?
No. You can, however, declare a matching method in the subclass. But regardless of how it looks, it is not an overriding method.
What access modifiers can apply to local variables?
only final
When would you consider using 'final' on a method that is in a superclass?
final keyword prevents a method from being overridden in a subclass, and is often used to enforce the API functionality of a method.
Can you have an abstract class that does not contain an abstract method?
An abstract class can be valid if it does not have any abstract methods.
What class members are able to use the synchronized modifier?
synchronized modifier can be applied only to methods—not variables, not classes, just methods.
What is the purpose of the modifier strictfp?
strictfp forces floating points (and any floating-point operations) to adhere to the IEEE 754 standard.
What class members can strictfp be used with?
Only classes and methods
What are declaration rules for using var-args?
1. Can only use one var-arg per method.
2. To declare a method using a var-arg parameter, you follow the type with an ellipsis (…), a space, and then the name of the array that will hold the parameters received.
3. The var-arg must be the last parameter in the method's signature, and you can have only one var-arg in a method.
Parameter type can be primitive or an object.
Example:
doStuff(Animal... animal)
What are the differences between a constructor and a method?
The first thing to notice is that constructors look an awful lot like methods. A key difference is that a constructor can't ever, ever, ever, have a return type…ever! Constructor declarations can however have all of the normal access modifiers, and they can take arguments (including var-args), just like methods. The other BIG RULE, to understand about constructors is that they must have the same name as the class in which they are declared. Constructors can't be marked static (they are after all associated with object instantiation), they can't be marked final or abstract
What are the two types of variables in Java
Primitives and Object References.
What are the eight types of primitive variables?
A primitive can be one of eight types: char, boolean, byte, short, int, long, double, or float.
What is the range of floating point types such as float and double?
float is 32 bits long
double is 64 bits long.
What modifiers can a local variable be associated with?
final
What are rules relating to initializaing local variables?
must be initialized before you try to use it
Describe what an array is including the types an array can hold? Can an array hold primitives and object references?
In Java, arrays are objects that store multiple variables of the same type, or variables that are all subclasses of the same type. Arrays can hold either primitives or object references,
How do you declare an array of primitives or an array of objects?
int [ ] myNumbers;
Customer[ ] customers;
alternate syntax is also valid:
int myNumbers[ ] ;
Customer customers [ ];
Why would you want to use one of the Collection types in java.util instead of using an array?
Collections can dynamically adjust their size where an array can not.
How would you declare a 2 dimensional array?
int [ ] [ ] myNumbers;
How do you declare an array using a fixed size?
You don't. You never specify the size in declaration. Size matters when the array is constructed.
What does final mean when a primitive variable is declared as final?
Once the variable is initialized the value will not be able to be changed for the life of the variable.
What does final mean when a object reference variable is declared as final?
Once the variable is initialized the object reference can not be used to refer to another object. You can modify the state of the variable but not the object that is being referenced.
There are no final objects, just final object references.
What can you declare as static in a class?
methods, instance variables, initialization block, nested classes.
Where can you define an enum?
An enum can be declared inside or outside of a class, but not inside of a method!
interface modifiers
abstract, public
method modifiers
-public, private, protected, default
- final, abstract, static, synchronized, strictfp, native
instance variable modifiers
-public, private, protected, de
fault
-final, static, transient, volatile

what's another name for an interface instance variable?
constant
how do you initialize an array
int[] myArray = new int[3]
method signature of the main
public static void main (String[] args)
can main be overloaded?
Yes!
T/F determine class visibility before determining member visibility
True. If a class cannot be accessed it's members cannot be accessed.

5 Overriding method rules


1. Same argument list


2. Same return type


3. Less restrictive access


4. Throw narrower exception


5. No override final method


6. No override static

Overloading method rules
1. Must different argument list
2. May have diff return type
3. May have diff access mod
4. May throw diff exception
T/F Object type not reference type determines which overridden method is used at runtime
True
Which is safer, downcasting or upcasting?
Upcasting, becuase assignment restrict the access capabilities of the new variable
What type of casting must be done explicitly and why?
Downcasting, because the reference variable referes to a subtype object and downcasting assigns the variable to a reference of the subtype (an animal becomes a horse)
What is the first statement of every constructor call?
this() - for overloaded constructor
or
super() - for no arg contructor
can constructors be inherited?
No. They can never be overriden either.
Can you have calls to this() and super() in the same constructor
No, never calls to both in the same constructor
When would you use super(param1, param2)
calls a superclass constructor that requires parameters
static init block vs init block
static { code here }
runs once when class is loaded
{ code here }
runs for every new instance
can static method access instance variables?
No! Unless the variable is static
What's the call order of init blocks and constructors
1. Static init blocks run when class is first loaded
2. Instance init blocks run after the constructor calls super()
3. instance init block runs everytime a class instance is created
4. init blocks execute in the order in which they appear
What are the 4 basic scopes
1. Static vars (class)
2. Instance vars (object)
3. Local vars (method)
4. Block vars (for, if, while...)
Give an example of this: reference variables can refer to subclasses of the declared type, but not to superclasses.
A boxer variable can refer to a dog object. But not an Animal object.
What is the finalize() method
It comes from the object class and it runs once before the garbage collector deletes an object/but it's not guaranteed
When does an object become eligible for garbage collection
when no live thread can reach it
The XOR ( "^" hat operand)
Evaluates to true if exactly one operand is true

In a switch statement what are the rules for the variable

It must be a literal or final variable. Declared and initialized I same line. Can use int, enum or string

What must you do with checked exceptions?

Must declare using throwS it must catch using try/catch

Which exceptions are unchecked?

Error and RuntimeException

When is the finally block executed?

Always, whether or not an exception is caught

In what order should catch blocks be used? why? give an example.

From most specific to most generic. IOException first then Exception last. If Exception was caught first then IOException would never be reached. This will cause a compiler error