Java-Default Value of Class Members

Default Value of Class Members

The member variable is declared but not defined, it is always default-initialized to a zero of the appropriate. Following table shows variables types and their default values :

Data Type Default value
char 0
int / short / long / byte 0
float / double 0.0
String null



Program Source

class Data{
    byte byt;
    int inte;
    float flot;
    String str;
    void defaultValues()
        System.out.println("byt     : "+byt);
        System.out.println("inte    : "+inte);
        System.out.println("flot    : "+flot);
        System.out.println("str     : "+str);

public class Javaapp {

    public static void main(String[] args) {
        Data d1 = new Data();

Leave a Comment