`
yaojingguo
  • 浏览: 201702 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Static method syntax difference between C++ and Java

阅读更多

Just a memo for me to remember the difference.

 

class Holder {
  public static void sayHello() {
    System.out.println("Hello, World!\n");  
  }
}

public class Foo  {
  public static void main (String [] args)  {
    Holder.sayHello();

    Holder h1 = new Holder();
    h1.sayHello();
  }
}
 #include <iostream>
#include <string>
using namespace std;

struct Holder {
  public:
    static void sayHello() {
      cout << "Hello, World!\n";
    }
};

int main(int argc, const char *argv[]) {
  Holder::sayHello(); 

  Holder h;
  h.sayHello();
  return 0;
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics