- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the default values of instance variables whether primitive or reference type in Java?
When we haven’t initialized the instance variables compiler initializes them with default values.
For boolean type, the default value is false, for float and double types default values are 0.0 and for remaining primitive types default value is 0.
Example
public class Sample { int varInt; float varFloat; boolean varBool; long varLong; byte varByte; short varShort; double varDouble; public static void main(String args[]){ Sample obj = new Sample(); System.out.println("Default int value ::"+obj.varInt); System.out.println("Default float value ::"+obj.varFloat); System.out.println("Default boolean value ::"+obj.varBool); System.out.println("Default long value ::"+obj.varLong); System.out.println("Default byte value ::"+obj.varByte); System.out.println("Default short value ::"+obj.varShort); System.out.println("Default double value ::"+obj.varDouble); } }
Output
Default int value ::0 Default float value ::0.0 Default boolean value ::false Default long value ::0 Default byte value ::0 Default short value ::0 Default double value ::0.0
- Related Articles
- What are class variables, instance variables and local variables in Java?
- Instance variables in Java
- Do local variables in Java have default values?
- What are the default array values in Java?
- What is the difference between class variables and instance variables in Java?
- List out the default values of numeric and non-numeric primitive data types in Java?
- Default value of primitive data types in Java
- Default values of static variables in C
- What are primitive data type in C++?
- Passing primitive values while instantiating a parameterized type (generic) in Java?
- Get the name of a primitive type in Java
- Is String a primitive data type or an object in Java?
- Is an array a primitive type or an object in Java?
- What is the default type of a bit value assigned to user variables?
- What are the default initialization values of elements in an array using Java?

Advertisements