久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

通過代碼實例解析JAVA類生命周期

瀏覽:5日期:2022-08-25 18:40:07

代碼

public class TestClass { public static int k=0; public static TestClass t1=new TestClass('t1'); public static TestClass t2=new TestClass('t2'); public static int i=print('i'); public static int n=99; public int j=print('j'); { print('構造塊'); } static { print('靜態塊'); } public TestClass(String str) { System.out.println((++k)+''+str+'i='+i+'n='+n); ++n; ++i; } public static int print(String str){ System.out.println((++k) +':' + str + ' i=' + i + ' n=' + n); ++n; return ++ i; } public static void main(String[] args){ System.out.println('=========start============'); TestClass t = new TestClass('init'); System.out.println('=========end============'); }}

執行結果

1:j i=0 n=02:構造塊 i=1 n=13t1i=2n=24:j i=3 n=35:構造塊 i=4 n=46t2i=5n=57:i i=6 n=68:靜態塊 i=7 n=99=========start============9:j i=8 n=10010:構造塊 i=9 n=10111initi=10n=102=========end============

講解

代碼由上到下 依次執行

由static修飾的變量或方法是在方法區,屬于類變量、類方法

new對象這個操作,new出來的對象在堆里 對象的引用在棧里

new出來的對象 方法快先構造方法執行

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Java
相關文章:
主站蜘蛛池模板: 旌德县| 紫阳县| 丁青县| 亚东县| 靖宇县| 庆云县| 弋阳县| 墨脱县| 保康县| 蒙阴县| 仙桃市| 张北县| 宣化县| 翁源县| 潢川县| 沙田区| 资中县| 衡水市| 弋阳县| 东方市| 武乡县| 寻乌县| 高碑店市| 新蔡县| 华坪县| 鲜城| 温州市| 双流县| 澳门| 彩票| 昭平县| 贺州市| 城口县| 岳池县| 龙里县| 嘉禾县| 海宁市| 共和县| 博白县| 东山县| 杨浦区|