【原創】Java面試題筆記

來源:互聯網
上載者:User

標籤:span   void   基本   box   pos   參數   log   val   函數調用   

 

  • 自動裝箱、拆箱
 1 public class IntegerTest { 2  3     @Test 4     public void constPool(){ 5         // 自動裝箱時,調用valueOf方法,預設會將-128 至 127 放常量池 6         Integer f1 = 100, f2 = 100, f3 = 150, f4 = 150; 7  8         System.out.println(f1 == f2); // true 常量池中 9         System.out.println(f3 == f4); // false 非常量池中,不同對象引用10     }11 12     @Test13     public void autoboxing(){14         Integer a = new Integer(3);15         Integer b = 3;16         int c = 3;17 18         System.out.println(a == b); // false 不同引用19         System.out.println(a == c); // true a自動拆箱成int類型20     }21 }
  • 棧(stack)、堆(heap)、靜態區(static area)

通常我們定義一個基礎資料型別 (Elementary Data Type)的變數,一個對象的引用,還有就是函數調用的現場儲存都使用記憶體中的棧空間;而通過new關鍵字和構造器建立的對象放在堆空間;程式中的字面量(literal)如直接書寫的100、”hello”和常量都是放在靜態區中。棧空間操作起來最快但是棧很小,通常大量的對象都是放在堆空間,理論上整個記憶體沒有被其他進程使用的空間甚至硬碟上的虛擬記憶體都可以被當成堆空間來使用。

String str = new String("hello");

上面的語句中變數str放在棧上,用new建立出來的字串對象放在堆上,而”hello”這個字面量放在靜態區。

  • 構造方法

子類預設繼承父類的無參數的構造方法。帶參數的構造方法不能繼承,也不能重寫,因為類名都不一樣了。

【原創】Java面試題筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.