Static and Final of Java-from complete reference of Java

原创 2006年06月07日 13:26:00

There will be times when you will want to define a class member that will be used independently of any object of that class. Normally a class member must be accessed only in conjunction with an object of its class. However, it is possible to create a member that can be used by itself, without reference to a specific instance. To create such a member, precede its declaration with the keywork static. When a member is declared static, it can be accessed before any objects of its class are created, and without reference to any object. You can declare both methods and variables to be static. The most common example of a static member is main(), main() is declared as static because it must be called before any objects exist.
Instance variables declared as static are, essentially, global variables. When objects of its class are declared, no copy of a static variable is made. Instead, all instances of the class share the same static variable.
Methods declared as static have several restrictions:
1.They can only call other static methods.
2.They must only access static data.
3.They cannot refer to this or super in any way.

Remeber: It is illegal to refer to any instance variables inside of a static method


Final:
A variable can be declared as fina. Doing so prevents its contents from being modified. This means that you initialize a final variable when it is declared.

相关文章推荐

Complete reference of all STSADM operations (with parameters) in MOSS 2007 SP1

This is an update to my complete reference of all STSADM operations in Microsoft Office SharePoint S...
  • Neccoo
  • Neccoo
  • 2011年12月22日 12:57
  • 507

LeetCode 19 — Remove Nth Node From End of List(C++ Java Python)

题目:http://oj.leetcode.com/problems/remove-nth-node-from-end-of-list/ Given a linked list, remove t...

LeetCode 19 Remove Nth Node From End of List (C,C++,Java,Python)

Problem: Given a linked list, remove the nth node from the end of list and return its head. ...

【LeetCode-面试算法经典-Java实现】【019-Remove Nth Node From End of List(移除单链表的倒数第N个节点)】

【019-Remove Nth Node From End of List(移除单链表的倒数第N个节点)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Given a l...

java微信退款unexpected end of file from server

首先抛出一个问题 unexpected end of file from server 相信很多人都会遇到这个问题,因为只要你做过微信支付然后再来做退款的时候就会习惯性地把支付的源码直接拿过来用,然后...
  • xb12369
  • xb12369
  • 2016年06月07日 11:15
  • 5605

LeetCode – Remove Nth Node From End of List (Java)

Given a linked list, remove the nth node from the end of list and return its head. For example, ...

LeetCode 19之Remove Nth Node From End of List的Java题解(三种解法)

题目: Given a linked list, remove the nth node from the end of list and return its head. For e...

《Effective_Java》 Item1:Consider static actor methods instead of constructors

使用静态工厂的优势 1.  不同于构造函数,可以赋予静态工厂更有意义的名字         eg. BigInteger的构造方法BigInteger(int, int, Random)返回一个可...
  • llsit
  • llsit
  • 2011年10月12日 23:01
  • 344
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Static and Final of Java-from complete reference of Java
举报原因:
原因补充:

(最多只允许输入30个字)