OCP learning Flashcards
may an abstract class have methods or fields declared static?
Yes
an abstract class may have methods or fields declared static
can the abstract keyword be applied to a field?
the abstract keyword can be applied to a class or a method but not to a field
–> no abstract variables
an abstract class can be derived from a concrete class?
an abstract class can be derived from a concrete class! Although the language allows it, it is not a good idea to do so.
wrapper classes –> final or not?
wrapper classes –> final class
- which kind of class cannot be extended?
- which kind of method cannot be overridden?
final and static class / methods
method of Final class –> final or not?
all methods of a final class are implicitly FINAL
what is blank final?
If a variable declaration defines a variable as final but did not initialize it, then it is referred to as blank final.
You need to initialize a blank final all the constructors you have defined in the class; otherwise the compiler will complain.
final parameters –> can be?
the keyword final can even be applied to parameters. The value of a final parameter cannot be changed once assigned.
meaning of final keyword:
- primitive
- object
- primitive –> value
- object –> refers to the object reference, not its state.
–> can change the internal state of the passed final object, but you cannot change the reference itself.