What is the difference between static and non-static
variables?

Answers were Sorted based on User's Feedback



What is the difference between static and non-static variables?..

Answer / sathya

Static variables:
There is only one copy of static variable and even
when the class is instatiated, the value remains the same.

Non-static variables:
Every time the class is instatiated, the objest has
their own copy of these variables.

Is This Answer Correct ?    72 Yes 13 No

What is the difference between static and non-static variables?..

Answer / ravikiran

static variables are class variables and the values remains
same fr the whole class
nonstatic variables are of two kinds
global variables:are the variables which defines variables
which can be accesible over the whole class
local variables:the scope of local variables is with tin
the method only

Is This Answer Correct ?    29 Yes 15 No

What is the difference between static and non-static variables?..

Answer / sandhya reddy

Static Variables are loading when class is loading to the JVM.

Non-Static Variables are loading only when an object is
creating for the particular class.Non- Static variables
can't use inside Static Methods untill and unless creating
an object of that class.with the object reference only we
can asle to use Non-static variables inside Static methods,
But inside Non-Static methods we able to use static
variables without creating any object.

Is This Answer Correct ?    11 Yes 6 No

What is the difference between static and non-static variables?..

Answer / javeed

* Non-static which ia(instence variable) can be accessed
only inside a non-sattic method.

* A static variable can be axxessed in both static and non-
static methods.

Is This Answer Correct ?    8 Yes 4 No

What is the difference between static and non-static variables?..

Answer / pravallika

in case of static variables memory can be allocated only at once and these variables can access with help of class name but where as non static variables have memory can be allocated in separate locations.And these variables can access with help of object

Is This Answer Correct ?    3 Yes 0 No

What is the difference between static and non-static variables?..

Answer / santosh mundhe

Static:1)Memory allocated before creation of object.
2)Gets memory on Global segment.
3)Object can't get copy of static variable, each
object shears static variable from global segment.
4)Static variables are not part ob object.

Non-static:
1)Gets memory on satck segment.
2)Object gets copy of non static variable.
3)Non static variables are part of object.

Is This Answer Correct ?    8 Yes 7 No

Post New Answer

More Core Java Interview Questions

Why java is call by value?

0 Answers  


what is a transient variable?

5 Answers  


How many types of voids are there?

0 Answers  


How do you remove duplicates from an array in java?

0 Answers  


What language is an assembler written in?

0 Answers  






What class is used to create Server side object?

1 Answers   TCS,


What is cr keyboard?

0 Answers  


Can a for statement loop indefinitely?

3 Answers  


What does I ++ mean?

0 Answers  


What is the purpose of format function?

0 Answers  


Is there any way to find whether software installed in the system is registered by just providing the .exe file? I have tried the following code but its just displaying the directory structure in the registry. Here the code : package com.msi.intaller; import java.util.Iterator; import ca.beq.util.win32.registry.RegistryKey; import ca.beq.util.win32.registry.RootKey; public class RegistryFinder { public static void main(String... args) throws Exception { RegistryKey.initialize(RegistryFinder.class.getResource("jRe gistryKey.dll").getFile()); RegistryKey key = new RegistryKey(RootKey.HKLM, "Software\\ODBC"); for (Iterator<RegistryKey> subkeys = key.subkeys(); subkeys.hasNext();) { RegistryKey subkey = subkeys.next(); System.out.println(subkey.getName()); // You need to check here if there's anything which matches "Mozilla FireFox". } } }

0 Answers   Google,


What are the characteristics of Final,Finally and Finalize keywords.

0 Answers   Flextronics,


Categories