The
default value for a Boolean (or any object) field is null.
The
default value for a boolean (primitive) field is false.
DemoClass.java
package com.sample.app;
public class DemoClass {
boolean primVariable;
Boolean objVariable;
}
App.java
package com.sample.app;
public class App {
public static void main(String[] args) {
DemoClass obj = new DemoClass();
System.out.println("Primitive : " + obj.primVariable);
System.out.println("Object : " + obj.objVariable);
}
}
Output
Primitive
: false
Object :
null
Reference
You may
like
No comments:
Post a Comment