Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-31-2008, 03:41 PM
eva eva is offline
Member
 
Join Date: Dec 2007
Posts: 49
eva is on a distinguished road
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:

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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-31-2008, 05:11 PM
jelly's Avatar
Member
 
Join Date: Jan 2008
Location: Somerset, UK
Posts: 46
jelly is on a distinguished road
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.

Code:
x = Math.sqrt(4);
__________________
-- Hope that helps
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-31-2008, 05:17 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
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:
Code:
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(".*");
(Just played with Regex ) I hope this helped.
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Math levent Java Tutorials 1 05-12-2008 10:03 AM
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String) baltimore New To Java 1 08-06-2007 08:45 AM
Help with math in java fernando New To Java 1 08-06-2007 07:05 AM
java.lang.OutOfMemoryError: Java heap space paul Advanced Java 1 07-25-2007 09:07 PM
java.lang.UnsatisfiedLinkError: no parport in java.library.path Heather NetBeans 2 06-29-2007 03:45 PM


All times are GMT +3. The time now is 08:12 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org