Home Discussion Discuss: Example of a class variable (static variable)

  • Javaakash August 18, 2011 at 8:08 PM

    can I call static variable with object also. or just class name is allowed?

  • correction jee October 13, 2011 at 3:27 PM

    The following statement is wrong: "As we can see in this example each object has its own copy of class variable." I guess you mean As we can see in this example all the object share the class variable "noOfInstances" (which counts the number of instances of class StaticVariable)

  • best illustration to understand static keywordIyyanarGopal December 12, 2011 at 12:49 PM

    I have been continuously searching for perfect example to understand "static" keyword.finally i found out here...am very much satisfied, the way they explained here..

  • static variables in javapaurnima ingale January 17, 2012 at 12:01 AM

    All instances of the same class share a single copy of the static variable.the static variables are initialise exactly when a class is loaded, i.e all static variable in a class are initialize before any object of that class can be created. we can initialize value to static variable, but if you dont explicitly initialize a static variable, it gets default value i.e 0

  • javakuna simhachalam January 12, 2013 at 5:06 PM

    Yes

  • about static variable/method...ranvijay singh rajput March 30, 2012 at 12:18 PM

    if a method is declared as a static than there is no need to create objet.we can directly call that method as following... classname.methodname(); where classname and methodname is declared as static. one thing more about static variable is that "non static variable cannot be used inside of a method which is declared as static." ex:- class room { int x,y; static getdata(int l,int b) { x=l; //here x andy is non static member y=b; //which is used in side static method } //that is not legal to write. }

  • about static member in javaarchana yadav October 21, 2012 at 11:51 PM

    please give the proper definition of static member with example in java.

  • javaprem jha November 1, 2012 at 5:08 PM

    static variable

  • Needs clarification...Mohsin November 26, 2012 at 3:03 PM

    But if we didn't increase the value in constructor then it gives us 0.... repetitively :/

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
Java Beginners

Static Variable
of a class, an object, is created. When static is applied to member variables, it means that the static variable is shared among all instances of the class...Static Variable  What is the basic use of introducing static variable 

Core Java

Static variable in java
; Classname.variablename; Example: Using Static Variable. public class Staticvariable... methods, variable inside a class and static class. Static variable is also called class variable which belongs to class not to object. Static 

General

Example of a class variable (static variable)
Example of a class variable (static variable)   ... you can define the static class variable in a class. When a number of objects... of a static variable first of all create a class StaticVariable. Define one static 

PHP Tutorial

PHP Static Variable and Methods
the all objects of that class. If we declare a method as static then we can access the method using class, without instantiating any object. Example of PHP Static... copy of the variable for the class. All objects of that class will access one copy 

Java Beginners

static
, The Static means that a certain object/variable is resident in memory and accessed each time an instance of a class, an object, is created. When static is applied to member variables, it means that the static variable is shared among all 

Java Beginners

static
redeclare static variable in the inherited class  can we redeclare static variable in the inherited class like this: public class StaticClass1 { class StaticClass1{ static int noOfInstances; StaticClass1 

Java Beginners

non static variable cannot be referenced from static context
non static variable cannot be referenced from static context  public class Add{ int foo=7; int bar=8; public int add(int x,int y... "non static variable cannot be referenced from static context". How to solve 

Java Beginners

non static variable cannot be referenced from static context
non static variable cannot be referenced from static context  public class Add{ int foo=7; int bar=8; public int add(int x,int y... public static void main(String []s){ Add a1=new Add(); a1.add(7,8 

Java Tips and Examples

Variable Names
. Class - Static variables are sometimes prefixed... Java Notes Variable Names Basic variable naming conventions Choosing good names is probably 

PHP Questions

static variable in php
static variable in php  How can i call a global variable as a static variable 

Java Beginners

how to inherit static variable
how to inherit static variable   how to inherit static variable or methods in Java?? Please explain the entire process of inheriting the variable. Thanks in advance 

Java Beginners

What is the importance of static variable?
What is the importance of static variable?  hi, What is the importance of static variable? thanks 

Java Beginners

STATIC VARIABLE DECLARATION
STATIC VARIABLE DECLARATION  why cannot the static variable declare inside the method 

Java Beginners

Local Variable and Instant Variable
Local Variable and Instant Variable  difference between Local Variable and Instant Variable   Difference between local variable and instance variable Instance variable is declared within a class but not within 

Java Beginners

Serialize the static variable
Serialize the static variable  hello, Can we serialize the static variable?   hii Yes we can serialize the static variable. if u don't want to serialize, u need to declare the variable as transient 

Java Tips and Examples

Instance variable in java
. Here are the various example to declare variable as below: int a,b,c... in java, they are as follows : Local variable Instance Variable class/static variable Instance variable : Instance variable are declared 

Java Beginners

Declare Reference variable
in memory when object is created. Static variable is class variable which... variable static int b; // static variable A ref; static... of object creation, but here i am declaring reference variable in class 

Java Beginners

how to pass class variable to another class
how to pass class variable to another class  i need to access a variable from a class to another class currently running at the same time. using... the following code: import java.util.*; class A { static int regd; static int 

Java Beginners

Store Variable in Java
Store Variable in Java  How to store Variables in Java?   public class DoubleTest { public static void main(String[] args) { double...(aDouble); // Outputs 7.21 } }   Variable in Java 

Flex Questions

Private variable of class
Private variable of class  Hi..... What keyword allows you to refer to private variables of a class in flex? Please give me an example for that Thanks  Ans: private keyword and this keyword 

Java Tips and Examples

Example of a instance variable
of the class. The example will show you how you can use a non-static variables... Example of a instance variable   ... class,  the same copy of  instance variable is provided to all 

Programming Tutorials

Java static method example
Description: Static variable are used within the static method. Non static variable do not exits in the static method. Static variables are shared by its class instances. Static variable can be used without using the instances 

Java Beginners

What is a local, member and a class variable?
What is a local, member and a class variable?   Hi, What is a local, member and a class variable? thanks 

Java Beginners

Initializing Integer Variable issue?
Initializing Integer Variable issue?  My program is supposed to take a phrase like you'd see on a TV commercial, for example: "Call 1-800-GETLOAN now... on how to shorten/optimize the code are welcome. Code below. public class 

Programming Tutorials

Local Variable ,Package & import
it is declared. Example of Local variable : The class variable are declared in the class... Variable public class LocalVar { public static void main(String args... the Class Variable public class ClassVar { private static int 

Java Beginners

store data from a variable in mysql?
is then saved to another table. import java.sql.*; class RetrieveData { public static...store data from a variable in mysql?  sir last time asked you tell me how to retrieve data from a database mysql and store it in an int variable 

Java Tips and Examples

Get Environment Variable Java
Get Environment Variable Java       In this example we are getting environment variable. To get... of the System class and gets the information about environment variable. get 

Programming Tutorials

Difference between the local and class variable.
Description: The class variable are declared in the class but not within methods of any class. Whereas the local variable exits within the methods of any... between the class and local variable. Showing Local Variable 

General

Using Unicode Variable Names - Java Tutorials
Using Unicode Variable Names 2001-11-23 The Java Specialists' Newsletter [Issue 036] - Using Unicode Variable Names Author: Dr. Heinz M. Kabutz... members are currently subscribed from 56 countries Using Unicode Variable 

Java Beginners

Can we declare a static variable inside a method?
Can we declare a static variable inside a method?   Hi, Can we declare a static variable inside a method? thanks 

DMCA.com