Results 1 to 3 of 3

Thread: java.lang.Math

  1. #1
    eva is offline Member
    Join Date
    Dec 2007
    Rep Power

    Default java.lang.Math

    java.lang.Math is not an Abstract class. So, we should be allowed to makes its instance. When I try to do so, I get an error:

    Java Code:
    Math obj = new Math();
    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    	The constructor Math() is not visible
    Why it is so?

    - PEACE

  2. #2
    jelly's Avatar
    jelly is offline Member
    Join Date
    Jan 2008
    Somerset, UK
    Rep Power


    Math has a private constructor - hence your error message - all its methods are static so there is never a need to instantiate on, e.g.

    Java Code:
    x = Math.sqrt(4);
    -- Hope that helps

  3. #3
    tim's Avatar
    tim is offline Senior Member
    Join Date
    Dec 2007
    Rep Power

    Default Math constructor

    Hello eva

    It is not always necessary to make a class abstract to prevent it from being instanced. If you omit the constructor or give the constructor some protected access, you can also prevent it from being instanced. It is also possible for other classes to use a method to create an instance of that class without a constructor. For example:
    Java Code:
    java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(".*");
    (Just played with Regex :D) I hope this helped. ;)
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

Similar Threads

  1. java.lang.OutOfMemoryError: Java heap space
    By paul in forum Advanced Java
    Replies: 11
    Last Post: 06-12-2010, 05:30 PM
  2. Replies: 3
    Last Post: 09-07-2009, 01:28 PM
  3. Replies: 2
    Last Post: 09-18-2008, 07:30 AM
  4. Java Math
    By levent in forum Java Tutorial
    Replies: 1
    Last Post: 05-12-2008, 09:03 AM
  5. Help with math in java
    By fernando in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 06:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts