Title: Unable to Create Math object in Java?
Tags: java
Question: I am trying to create an object of the Math in Java. Ideally there is no need of creating such an instance as it only has static methods and parameters. I just want to create it whether it will allow me or not. So when I am creating a math class object, compiler error is displayed saying that the Math class constructor is not visible.
But I looked into the Math class code and there is no explict constructor provided, so java will provide a default constructor, which can be accessed outside.
Comment: Please, could you post your code?


Here is another answer: This is from Java docs.
public final class Math {
/**
* Don't let anyone instantiate this class.
*/
private Math() {}
The documentation comment itself is sufficient to answer your question.

Here is another answer: This is correct behavior. The constructor for Math is private as it only contains static utility methods:
private Math() {}
Comment for this answer: Thanks for the answer.  I just want to know what are the utility methods in java
Comment for this answer: They are exactly as you see in `Math`. Stateless helper methods that typically have no dependency on instance variables or _state_ and are deterministic. Also see this [link](http://www.coderanch.com/t/479357/java/java/utility-methods)

Here is another answer: If you look at the Math class definition, its constructor is private:
private Math() {}
This means that the creator of the class does not want the user to be able to create instances of this class. It makes sense because it's a utility class, which means any method inside the class does not depened on the state of the object. You just need to pass the method parameter values and it will simply give you the intended result. That's why all the methods inside the Math class are static.

Here is another answer: You can't do it because its constructor is private. You don't see the constructor in the API because private methods are not listed.
For example take this example:
public class SampleClass {
private static int var1 = 1;
private static int var2 = 1;
private static int var3 = 1;
private SampleClass () {
// This constructor will prevent the default constructor from being invoked
public static void runMethod1() {
System.out.println("Value is:" + var1);
public static void runMethod2() {
System.out.println("Value is:" + var2);
public static void runMethod3() {
System.out.println("Value is:" + var3);
You can only create an instance of this class from inside the same class. If you try to create it from elsewhere, you will fail.
Comment for this answer: Update based on the example given.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 4, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:02/09/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<java>', 'Title': 'Unable to Create Math object in Java?', 'ViewCount': 2656, 'id': 14789512, 'user_AboutMe': None, 'user_AccountId': 2347469.0, 'user_DisplayName': 'user2057312', 'user_Reputation': 33.0, 'user_Views': 18.0, 'user_id': 2057312.0}}