| Author |
Which is the best practice?
|
Jean Fore
Ranch Hand
Joined: Feb 23, 2006
Posts: 33
|
|
Can anyone suggets wjich is the best practice for a small program like this? Practice 1: public class Temperature { public static void main(String args[]) { double fahrenheit = 62.5; double celsius = f2c(fahrenheit); System.out.println(fahrenheit + "F = "+celsius +"C"); } static double f2c(double fahr) { return (fahr=32)*5/9; } } Practice 2 : public class Temperature { public static void main(String args[]) { double fahrenheit = 62.5; Temperature inst = new Temperature(); double celsius = inst.f2c(fahrenheit); System.out.println(fahrenheit + "F = "+celsius +"C"); } double f2c(double fahr) { return (fahr=32)*5/9; } } Thanks Jean
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24061
|
|
|
For a program this tiny, it obviously doesn't really matter. But you don't want to get into the habit of making everything a static method. As you write more code, you should use statics less and less.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Jean Fore
Ranch Hand
Joined: Feb 23, 2006
Posts: 33
|
|
Thank you so much for the immediate response. All I wanted to know was how good is the practice of using 'static' methods often!! Thanks a lot. -Jean.
|
 |
 |
|
|
subject: Which is the best practice?
|
|
|