English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

This is reg Java programming

2006-10-22 17:29:03 · 3 answers · asked by venkatesh.r 2 in Computers & Internet Programming & Design

3 answers

U have heard a lot. Now listne from me. It will definitely help u.

Normally to access a class member (variable, method), u need an object of that class. However, it's possible to create a member that can be accessed without reference to a specific instance of the class. To create such a member u declare it with the keyword static.

For the rest see page 141 of "the Complete reference java" J2se 5 Edition, By Herbert Schildt. Name of the topic is "Understanding Static". It is explained there beautifully.

OK?

2006-10-24 08:02:17 · answer #1 · answered by binaryFusion 5 · 0 0

static marks a field or method that is shared by all instances of a class. Some people state the same idea by saying that static methods or fields belong to the class not to any particular instance.

Since a static member of a class does not belong to a class instance you can access it without having a particular instance of the class. This feature is useful for named constants in interfaces, or for the "getInstance" method for an implementation of the singleton pattern.

Here are some examples.

public interface Foo {
public static final int BAR = 42;
}

BAR can be accessed like this Foo.BAR. Notice the use of a type rather than an instance of that type as an accessor.

Here is the classic singleton setup

public class Singleton {
 private static Singleton instance = null;
 public static Singleton getInstance(){
  if (instance == null ){instance = new Singleton();}
  return instance;
  }
 protected Singleton(){}
}

2006-10-23 00:54:16 · answer #2 · answered by run4ever79 3 · 0 0

Nonsense apart!

Static does what it means . irrespective of the language (thank god programmers has followed some universal rules here ) the role of static is to alocate the SINGLE SPACE for the a static variable and initialize it to 0 (at first) .. then every reference to this by any object or STATIC CLASS , directly access the memory area and flirts with the value.

hope it helps

All the best !

2006-10-24 14:10:08 · answer #3 · answered by indianYogi 2 · 0 0

fedest.com, questions and answers