第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

最后的pri2 hello2=new pri2()是怎么運行的?

package com.imooc;

public class pri2{
?? ?int num1;
?? ?int num2;
?? ?static int num3;
?? ?public pri2(){
?? ??? ?num1=91;
?? ??? ?System.out.println("通過構(gòu)造方法為變量num1賦值");
?? ??? ?}
?? ??? ?{
?? ??? ??? ?num2=74;
?? ??? ??? ?System.out.println("通過初始化模塊為num2賦值");
?? ??? ?}
?? ??? ?static{
?? ??? ??? ?num3=83;
?? ??? ??? ?System.out.println("通過靜態(tài)初始化模塊為怒目賦值");
?? ??? ?}
?? ??? ?public static void main(String[] args) {
?? ??? ??? ?pri2 hello=new pri2();
?? ??? ??? ?System.out.println("num1:"+hello.num1);
?? ??? ??? ?System.out.println("num2:"+hello.num2);
?? ??? ??? ?System.out.println("num3:"+num3);
?? ??? ??? ?pri2 hello2=new pri2();
?? ??? ?}
?? ?}

正在回答

2 回答

pri2 hello=new pri2();
?? ??? ??? ?System.out.println("num1:"+hello.num1);
?? ??? ??? ?System.out.println("num2:"+hello.num2);
?? ??? ??? ?System.out.println("num3:"+num3);
?? ??? ??? ?pri2 hello2=new pri2();

這些代碼等同于

pri2 hello=new pri2();

?pri2 hello2=new pri2();

?? ??? ??? ?System.out.println("num1:"+hello.num1);
?? ??? ??? ?System.out.println("num2:"+hello.num2);
?? ??? ??? ?System.out.println("num3:"+num3);

num3屬于靜態(tài)類只能被執(zhí)行一次,所以執(zhí)行結(jié)果缺少“”通過靜態(tài)初始化塊初始化? num3“ ? ? ? ??

0 回復 有任何疑惑可以回復我~

Static修飾的類成員,它的使用完全獨立于該類的任何對象。Static塊僅在該類被加載時執(zhí)行一次。

0 回復 有任何疑惑可以回復我~
#1

Chen十八 提問者

非常感謝!
2017-04-22 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

最后的pri2 hello2=new pri2()是怎么運行的?

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號