@@ -420,7 +420,7 @@ the uninitialized variable, we can get different behavior depending on __what ty
420420with (primitives or objects)__ . The behavior also depends on __ the level (scope) at which we are declaring our
421421variable__ .
422422
423- Default values for Instance variables (Primitive and Non-primitive):
423+ #### Default values for Instance variables (Primitive and Non-primitive):
424424
425425Variable Type | Default Value
426426--------------|----------------
@@ -430,6 +430,41 @@ Variable Type | Default Value
430430` char ` | ` '\u0000' `
431431Object reference | ` null ` (not referencing any object)
432432
433+ Therefore, for the below program:
434+
435+ {% highlight java linenos %}
436+ public class Book {
437+ private String title; // instance reference variable
438+ private int noOfPages; // instance primitive variable
439+ public String getTitle() {
440+ return title;
441+ }
442+ public int getNoOfPages() {
443+ return noOfPages;
444+ }
445+ public static void main(String [ ] args) {
446+ Book b = new Book();
447+ System.out.println("The title is " + b.getTitle());
448+ System.out.println("No. of pages are " + b.getNoOfPages());
449+ }
450+ }
451+ {% endhighlight %}
452+
453+ The output will be:
454+ ` The title is null `
455+ ` No. of pages are 0 `
456+
457+ __ NOTE:__ ` null ` is not the same as an empty ` String ("") ` . A ` null ` value means the reference variable is not referring
458+ to any object on the heap.
459+
460+ #### Array Instance Variable
461+
462+
463+
464+ #### Default values for Local (also called Stack or Automatic) variables (Primitive and Non-primitive):
465+
466+
467+
433468{% include responsive_ad.html %}
434469
435470### Q&A
0 commit comments