国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

key word 'static' in c++/java

2019-11-11 05:06:17
字體:
來源:轉載
供稿:網友

   古人云“溫故而知新”,我挺喜歡這句話的,不過若不溫故,就遺忘了,更何況知新?

Comparison of static keyWord in C++ and java

Static keyword is used for almost same purpose in both C++ and Java. There are some differences though. This post covers similarities and differences of static keyword in C++ and Java.

Static Data Members: Like C++, static data members in Java are class members and shared among all objects. For example, in the following Java PRogram, static variable count is used to count the number of objects created.

Static Member Methods: Like C++, methods declared as static are class members and have following restrictions:

1) They can only call other static methods. For example, the following program fails in compilation. fun() is non-static and it is called in static main()

2) They must only access static data.

3) They cannot access this or super . For example, the following program fails in compilation.

Like C++, static data members and static methods can be accessed without creating an object. They can be accessed using class name. For example, in the following program, static data member count and static method fun() are accessed without any object.Static Block: Unlike C++, Java supports a special block, called static block (also called static clause) which can be used for static initialization of a class. This code inside static block is executed only once. See Static blocks in Java for details.

Static Local Variables: Unlike C++, Java doesn’t support static local variables. For example, the following Java program fails in compilation.


上一篇:C++運算符重載基礎

下一篇:C++ 初學

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 蚌埠市| 廉江市| 商都县| 大同县| 和顺县| 霞浦县| 积石山| 拜泉县| 呼伦贝尔市| 祥云县| 鹤山市| 南投县| 沙湾县| 鄂托克旗| 乐至县| 高平市| 房产| 古浪县| 迭部县| 华阴市| 新邵县| 兴和县| 罗江县| 酒泉市| 东阳市| 西青区| 永寿县| 孟连| 肇东市| 汤阴县| 黄梅县| 清镇市| 乳山市| 南澳县| 含山县| 广宗县| 界首市| 民和| 石家庄市| 万州区| 阜南县|