Results 1 to 3 of 3
Thread: java.lang.Math
- 01-31-2008, 02:41 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 49
- Rep Power
- 0
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:
Why it is so?Java Code:Math obj = new Math(); Exception in thread "main" java.lang.Error: Unresolved compilation problem: The constructor Math() is not visible
- PEACE
- 01-31-2008, 04:11 PM #2
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
- 01-31-2008, 04:17 PM #3
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:
(Just played with Regex :D) I hope this helped. ;)Java Code:java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(".*");Eyes dwelling into the past are blind to what lies in the future. Step carefully.
Similar Threads
-
java.lang.OutOfMemoryError: Java heap space
By paul in forum Advanced JavaReplies: 11Last Post: 06-12-2010, 05:30 PM -
java.lang.UnsatisfiedLinkError: no parport in java.library.path
By Heather in forum NetBeansReplies: 3Last Post: 09-07-2009, 01:28 PM -
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String)
By baltimore in forum New To JavaReplies: 2Last Post: 09-18-2008, 07:30 AM -
Java Math
By levent in forum Java TutorialReplies: 1Last Post: 05-12-2008, 09:03 AM -
Help with math in java
By fernando in forum New To JavaReplies: 1Last Post: 08-06-2007, 06:05 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks