Hi,
What is the reason they are different.. Both are serving same purpose right?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Riddhi ValechaPosted May 6, 2013, 11:43 PM
Static methods and variables-
Eg-
class A
{
public static int i=10;
public static int j;
public static method1()
{}
public static void Main()
{
int j = A.i;
A.method1();
A.j=20;
}
}
We can change the values of static variables.
Static variables and methods are called by classname. Class objects are not used to call static variables and methods.
------
Eg-
Class A
{
public constant int i=10;
public static void main()
{
A a = new A();
int j = a.i;
}
}
---
Constants variables have to be declared and initialized at the point of declaration. The values of constants cannot be changed.
Suma MPosted May 9, 2013, 12:12 AM
Jignesh TrivediPosted May 6, 2013, 11:39 PM
hi,
a static variable is a variable that can be used in different place and we can change it value with in our project and it share between multiple form or class.
we may change the value of static variable in any where prom application.
we can assign value in static variable at run time.
Constant is different, name suggest it self we can not change it value. value assign in constant variable at complied time only.
it must be initialized at declaration time
In short, both are fundamentally different and it depend on requirement when use which.
hope this will help you.