31 - 60 Flashcards
NumberFormatException
o base class o function?
o thrown to indicate that the application has tried to convert a string (with an inappropriate format) to one of the numeric types
o subclass of IllegalArgumentException
ClassCastException –> what is?
is thrown when an object fails an IS-A test with the class type to which it’s being cast
if not overload toString() –> what will be printed?
object’s name + hashCode()
can use “this” within static Method?
no
order of execute (2)
o direct superclass must be initialized
o SIC way
what is for-each loop?
How to read: for(String day : days)
enhanced for loop
which kind of access modifiers can be set to top class?
public, default
no protected & private
short b = 3;
b += 4.6;
output? Nguyên tắc cast của operand
o implicit cast to the type in left
o result = 7
cách viết main method
public static void main(String[] args){
public static void main(String args[]){
static public void main(String args[]){
how many public class / interface can be in a Java file? Name?
only 1 + same name as this file
limit of enhanced for loop with: array, collection
- cannot be used to initialize an array + modify its elements
- cannot be used to delete or remove the elements of a collection
- can’t iterate over multiple collections or arrays in the same for-each loop
exception handling –> order of exception
derived class –> base class
where in the constructor can super, this be used?
first statement
exception
o overriding - overridden method
o constructor - base constructor
overriding method / constructor can
- only throw
1. 1. exceptions that are declared in the throws clause of the overridden method
1. 2.exceptions that are subclasses of the declared exceptions - choose NOT to throw any exception
if a method uses another method that may throw a checked exception –> what does this method need? (2)
- the method should be enclosed within a try-catch block
- the method should specify this exception to be thrown in its method signature