position | ease | box | interval | due |
---|---|---|---|---|
front | 2.50 | 3 | 6.00 | 2021-01-26T23:35:21Z |
When there are no constructor explicitly defined, the compiler will use a default constructor.
As long as a constructor is defined, no-arg constructor is provided by the compiler any more.
When fields of a Class are Primitive Types, they have default values; when they are objects, they must be given an initial value, unless by using a Run Time Error (exception) will be thrown.
Local variables must be initialized.
int x; // x will get some arbitrarty value
, use before assigned a value will cause Compile Time Error
position | ease | box | interval | due |
---|---|---|---|---|
front | 2.50 | 3 | 6.00 | 2021-01-26T23:38:09Z |
Consider a class called Dog
:
Dog
,
the Java interpreter locate Dog.class
Dog
object on the heap and wipe it to zerothis
keywordposition | ease | box | interval | due |
---|---|---|---|---|
front | 2.50 | 3 | 6.00 | 2021-01-26T23:38:18Z |
position | ease | box | interval | due |
---|---|---|---|---|
front | 2.50 | 3 | 6.00 | 2021-01-26T23:30:49Z |
Java Garbage Collector first calls finalize()
when it’s ready to release objects' storage,
then on second pass of garbage-collection, it reclaim the objects' memory.
The need for finalize()
is limited to special cases where
objects can allocate storage in some way other than creating an object.
finalize()
may not be called, so if a resource must be released,
write another method and call it explicitly.
finalize()
in this case can serve as a reminder/checker
whether the release method has been called (prevent unknown memory leaks)