国产激情久久久久影院小草_国产91高跟丝袜_99精品视频99_三级真人片在线观看

Java中靜態(tài)變量的適用場(chǎng)景

時(shí)間:2020-09-05 14:29:15 JAVA認(rèn)證 我要投稿

Java中靜態(tài)變量的適用場(chǎng)景

  Java類(lèi)中的'靜態(tài)變量在程序運(yùn)行期間,其內(nèi)存空間對(duì)所有該類(lèi)的對(duì)象實(shí)例而言是共享的,有些時(shí)候可以認(rèn)為是全局變量。因此在某些時(shí)候?yàn)榱斯?jié)省系統(tǒng)內(nèi)存開(kāi)銷(xiāo)、共享資源,可以將類(lèi)中的一些變量聲明為靜態(tài)變量,通過(guò)下面的例子,你可以發(fā)現(xiàn)合理應(yīng)用靜態(tài)變量帶來(lái)的好處:

  Java代碼

  public class WeekA{

  static class Data {

  private int week;

  private String name;

  Data(int i, String s) {

  week= i;

  name = s;

  }

  }

  Data weeks[] = {

  new Data(1, "Monday"), new Data(2, "Tuesay"), new Data(3, "Wednesday"), new Data(4, "Thursday"), new Data(5, "Friday"), new Data(6, "Saturday"), new Data(7, "Sunday")

  };

  public static void main(String args[]) {

  final int N = 10000;

  WeekA weekinstance;

  for (int i = 1; i <= N; i++){

  weekinstance = new WeekA ();

  }

  }

  }

  public class WeekA{

  static class Data {

  private int week;

  private String name;

  Data(int i, String s) {

  week= i;

  name = s;

  }

  }

  Data weeks[] = {

  new Data(1, "Monday"), new Data(2, "Tuesay"), new Data(3, "Wednesday"), new Data(4, "Thursday"), new Data(5, "Friday"), new Data(6, "Saturday"), new Data(7, "Sunday")

  };

  public static void main(String args[]) {

  final int N = 10000;

  WeekA weekinstance;

  for (int i = 1; i <= N; i++){

  weekinstance = new WeekA ();

  }

  }

  }

【Java中靜態(tài)變量的適用場(chǎng)景】相關(guān)文章:

php靜態(tài)成員變量分享11-25

php中static靜態(tài)變量的使用方法11-16

Java中import的使用09-21

Java中接口的使用09-30

CSS中關(guān)于變量的基本教程詳解11-20

動(dòng)畫(huà)場(chǎng)景設(shè)計(jì)中的色彩應(yīng)用09-19

在java中Synchronized的用法05-15

Java中的動(dòng)態(tài)代碼編程06-05

Java中g(shù)oto實(shí)現(xiàn)方法09-24