-1
class D 
    {
        public static void main(String[] args) 
            {
                D d;   // d is a reference variable of class D. what is its value?
                System.out.println(d);//An initializing error occurs.
            }
   }

Above given is a java program having A class name D which is referred to a reference variable d. I want to know what is the default value of d as of an uninitialized variable

PM 77-1
  • 12,933
  • 21
  • 68
  • 111

1 Answers1

1

It's gives an error because d is a local variable and all local variables must be initialized before they can be referenced. If d were to be an instance variable then the default value would be null. That said to fix the error in your code you have to fix a default value for d.

D d = null;
cdaiga
  • 4,861
  • 3
  • 22
  • 42