Pin It

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 :

Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot