Java Programming Tutorial - 41 - Building Objects for Constructors

0 Sumanpal Singh · March 9, 2015

why we used this


public String toMilitary(){
 return String.format("%02d:%02d:%02d", getHour(), getMinute(), getSecond());
  }


this also works

public String toMilitary(){
 return String.format("%02d:%02d:%02d", hour, minute, second);
  }


Post a Reply

Replies

Oldest  Newest  Rating
0 Cristian Rosu · March 9, 2015
The first one uses 3 methods to display the time so he used that for learning purposes. The second one also works and it's a lot simpler but i think we learned more from the first one.
0 Branislav Lazic · March 9, 2015
It's called: "Good programming practice".
0 Sumanpal Singh · March 9, 2015
Thanks
  • 1

Java / Android Development

107,247 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator