Default Constructor

In this example, class Time1 does not declare a constructor, so the class has a default constructor that’s supplied by the compiler. Each instance variable implicitly receives the default value 0 for an int. Instance variables also can be initialized when they’re declared in the class body, using the same initialization syntax as with a local variable.

 1   // Fig. F.1: Time1.java 2   // Time1 class declaration maintains the time in 24-hour format. 3  4   public class Time1 5   { 6      private int hour; // 0 - 23   7      private int minute; // 0 - 59  8      private int second; // 0 - 59  9 10      // set a new time value using universal time; throw an11      // exception if the hour, minute ...

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.