Why Static variable required in java?For ex,class A
{
static int a;
int b;
}
Why static is required?

Answers were Sorted based on User's Feedback



Why Static variable required in java?For ex,class A { static int a; int b; } Why static is requ..

Answer / za

because it help us to declare class field asglobal variable

Is This Answer Correct ?    3 Yes 0 No

Why Static variable required in java?For ex,class A { static int a; int b; } Why static is requ..

Answer / sumit pal singh

static keyword is mainly used for memory management purpose. And static variable is used for declare the common property of object.

Is This Answer Correct ?    3 Yes 0 No

Why Static variable required in java?For ex,class A { static int a; int b; } Why static is requ..

Answer / aswini

Without using instance of the class means no need to use the class object to call static variable insted directly use the classname to use the static variable.moreover ,only one copy of static varible avaible to use all the classes.

Is This Answer Correct ?    2 Yes 0 No

Why Static variable required in java?For ex,class A { static int a; int b; } Why static is requ..

Answer / soumya

what is the advantage to declare a var as static instead of instance var..can you please tell me in brief?

Is This Answer Correct ?    1 Yes 0 No

Why Static variable required in java?For ex,class A { static int a; int b; } Why static is requ..

Answer / vaishnavi

To answer Soumya's question, instance variables are declared at class level, but the instance variables still belong to an instance/object. But static variables belong to a class.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

Can you have two constructors in java?

0 Answers  


What is difference between filereader and bufferedreader?

0 Answers  


What does microservices mean?

0 Answers  


Can we have multiple catch block for a try block?

0 Answers  


What is palindrome in java?

0 Answers  






Does sprintf add a null terminator?

0 Answers  


What is difference between string and stringbuffer?

0 Answers  


What is the purpose of return statement?

0 Answers  


How to find the largest value from the given array.

0 Answers  


Write a program to find maximum and minimum number in array?

0 Answers  


for(i=0;i<100;i++) { int i=method();//method returns no's from 1 to 10; /* insert some stmts which can give output like no.of times numbers(1-10) returned. (for example if it returns 2 then i want output how many times 2 returned) like that i want output for no's 1 - 10 how many times each no returned. */ }

3 Answers  


Is void a type?

0 Answers  


Categories