• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.Math constructor  RSS feed

 
Ajitha Satish
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is Math having private constructor? If it is having why is it not visible in API?
 
Andrey Kozhanov
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has. And what's the problem with not being visible in the api? You can't create Math instance in any case.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.Math is designed to be an Utility class and it has only static methods which dont require an instance to access!

and Welcome to javaRanch Ajitha
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Private members aren't part of the Application Programming Interface.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is given in the Java™ Language Specification as an example of how to prevent instantiation.
 
Javin Paul
Ranch Hand
Posts: 297
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

concept of utility class generally have Static method to access by using class name. As they are common to all it doesn't make sense to creating different instances and making them behave statically make lot of sense.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!