Thinking in Java 筆記

一、Method: less

Object-oriented programming is often summarized as simply "sending messages to objects" ide

二、byte: 函數

The size of each of char in a String is 16 bit, or two bytes,to support Unicode characters; code

三、OverLoading with primitives ci

A primitive can be automatically promoted from a smaller type to a larger one;example: element

f(long l){},f(float f){},f(double d){}  execute: int a=0; f(a); It will be call f(long l) method; it

char produces a slightly different effect,since if it doesn't find a exact char match, it is promoted to int; io

others: f(long l) {},f(folat f){} execute: double d=0; f(d)--->error ,f((long)d) and f((float)d) are right; ast

四、You simply use new to create the elements in the arrary; class

int [] a;   int [] b = new int[10];

五、Non-static instance initialzation ;

public Class A {

    private int a;

    {

    a = 10;

    }

}

This syntax is necessary to support the initialization of anonymous inner calsses;

六、final and private 

Any private methods in a class are implicitly final ,Because you can't access a private method, you can't override it.

This issue can confusion ,because if you try to override a private  method, its seems to work, and the complier doesn't give an error message;

"Overriding" can only occur if something is part of the base=class interface. That is , you must be able to upcast an object to its base type and call the same method ;

七、late binding

All method binding in Java uses late binding unless the method is static or final(private methods are implicitly final)

八、初始化類,先初始化父類,觸發父類初始化的方式不是在子類的構造函數中;

相關文章
相關標籤/搜索