stactic function

来源:互联网 发布:2345软件大全官方网站 编辑:程序博客网 时间:2024/05/16 06:30

Static methods neither require an instance of the class nor can they implicitly access the data (or thisselfMe, etc.) of such an instance. A static method is distinguished in some programming languages with the static keyword placed somewhere in the method's signature.

In statically typed languages such as Java, static methods are called "static" because they are resolved statically (i.e. at compile time) based on the class they are called on and not dynamically as in the case with instance methods which are resolved polymorphically based on the runtime type of the object. Therefore, static methods cannot be overridden.[7]

一句话, 类的静态成员函数是通过 类名 或者对象名调用,不需要this pointer, 而非静态成员函数需要 this pointer, 调用只能通过对象名调用。  想想类的今天成员变量是属于类本身的, 而不属于任何对象。 无论静态成员函数还是非静态的, 都是属于共享内存的, 是属于类的。 但是每个对象具有属于自己的非静态的成员变量。 

0 0