国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

通過代碼實(shí)例解析JAVA類生命周期

瀏覽:2日期: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('構(gòu)造塊'); } static { print('靜態(tài)塊'); } 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============'); }}

執(zhí)行結(jié)果

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

講解

代碼由上到下 依次執(zhí)行

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

new對(duì)象這個(gè)操作,new出來的對(duì)象在堆里 對(duì)象的引用在棧里

new出來的對(duì)象 方法快先構(gòu)造方法執(zhí)行

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 宁德市| 廉江市| 元谋县| 北海市| 济源市| 綦江县| 余干县| 普定县| 托克逊县| 永顺县| 于都县| 呼玛县| 彭水| 确山县| 隆化县| 林州市| 安远县| 江安县| 万荣县| 潍坊市| 海口市| 贞丰县| 城固县| 伊通| 九寨沟县| 策勒县| 桃源县| 方城县| 钟祥市| 化州市| 马边| 巫山县| 新源县| 桃园市| 青浦区| 砚山县| 天台县| 随州市| 调兵山市| 海南省| 聂拉木县|