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

Which is better singleton or static class?

0 Answers  


What is difference overloading and overriding?

0 Answers   Cyient,


what is difference between colection and collections?

25 Answers   Amdocs, IBM, Infosys, Ipog Software, Polaris, Tech Mahindra,


What is the difference between the file and randomaccessfile classes?

0 Answers  


Can we write method inside a method in java?

0 Answers  


What is the primitive type byte?

0 Answers  


How to convert string to int in java?

1 Answers  


Difference between nested and inner classes ?

0 Answers  


What will be the output of the program? public class Test { public static void main(String args[]) { ArrayList<String> list = new ArrayList<String>(); list.add("2"); list.add("3"); list.add("4"); list.add("5"); System.out.println("size :"+list.size()); for(int i=0;i<list.size();i++) { list.remove(i); } System.out.println("size after:"+list.size()); } }

5 Answers   Rolta,


how can u handle run time exception in java? explain with brief explanation with examples?

2 Answers   CTS,


What is r in java?

0 Answers  


Is oracle charging for java?

0 Answers  


Categories