01 - 30 Flashcards
Narrowing conversion
- what is it?
- how to do?
o bigger than int
o equals / smaller than int
- bigger –> smaller
- bigger than int –> need casting
- equals / smaller than int –> do not need casting
implicit promotion:
- operand
- int argument –> accept char?
- operands of mathematical operators are ALWAYS promoted to AT LEAST int and the return value will be AT LEAST int
- method takes int as argument –> can also takes char
- -> char will be implicitly promoted to int
casting requirements (2)
- IS_A relationship
(left hand side = super class) - compatible data type
hierarchy Exception
-
what must be imported if want to use ArrayList?
import java.util.ArrayList;
o how to know the number of elements in Array and ArrayList
o length of String & StringBuilder
o array –> .length
o ArrayList –> .size()
o String & StringBuilder –> .length()
array delaration:
- new is required?
- new is not required?
o 1 line –> not required
o 2 line –> required
operator + when use with String (concatenation) –> vị trí của “ “ ảnh hưởng ntn?
-
how do derived classes use the variables and methods defined in the superclass?
directly as if they were defined in their own classes
properties of final:
o class o method o variable + how must it be initialized? o interface
- final class cannot be extended by another class
- final method cannot be overridden
- final variables cannot be reassigned a value but can call methods on this variable
o final variable must be explicitly initialized in the same line of code or initialization block - kein final interface
when is a variable marked as eligible to be garbage collected? (2)
- can know which are eligible but not sure when
- when this object can no longer be accessed
o object’s reference variable is assigned an explicit null value or is reinitialized
o this object goes out of scope
4 loại access modifiers + range of accessability
public > protected > default > private
can static method access non-static variable?
no
can use this and super in a static method?
no
super.method # BaseClassName.method?
BaseClassName.method only applies to static method
super –> no limit