Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

Program to demonstrate default values for fields in Java

Program to demonstrate default values for fields in Java

public class Light {

  static int counter;
  static int counter2 = 100;
    
  int watts;
  int watts2 = 100;
  boolean indicator;
  String location;

  public static void main(String[] args) {
      
     Light light = new Light();
  
     System.out.println("static variable counter : "
                                     + Light.counter);
     System.out.println("static variable counter2 : "
                                     + Light.counter2);
     System.out.println("instance variable watts : "
                                     + light.watts);
     System.out.println("instance variable watts2 : "
                                     + light.watts2);
     System.out.println("instance variable indicator : "
                                     + light.indicator );
     System.out.println("instance variable location : "
                                     + light.location);

  }

}


Output of the program :

 
© 2021 Learn Java by Examples Template by Hubberspot