What is the default value of local variable?

Questions by deepesh.ms

Showing Answers 1 - 20 of 20 Answers

saravanan

  • Oct 4th, 2006
 

  There is no default value for local variables.Only the class varibles have default value.Example int take 0 as default value ,char take uoooo,string as null.

  Was this answer useful?  Yes

Abhijit

  • Nov 16th, 2006
 

Compiler never assigns a default value to a local variable. Unassigned local variables will result in compile time error.

  Was this answer useful?  Yes

Srilatha

  • Dec 5th, 2006
 

No default value for a local variable.It will give u compilation error when u try to pass that variable as argument to System.out.println statement.

  Was this answer useful?  Yes

bihag

  • Mar 17th, 2007
 

JAVA does not give Default value for local variables. You must give value to local variable before u going to use it otherwise it will give error.

  Was this answer useful?  Yes

Gaurav Arora

  • Sep 5th, 2011
 

JVM never assigns any default value to local or method variables. You have to initialise these variables before using them. Any attempt to use these variables without initialising them will result in compilation error.
However, JVM initialises the instance aur class level variables with their defaul values.

In case of uninitialised objects a null value is assigned to the reference of the object. Accessing this uninitialised objects will result in NullPointerException.

  Was this answer useful?  Yes

Kishan

  • Oct 28th, 2016
 

0 is default value of local variable and also global variable and character do not set anything by default..

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions