aspose file tools*
The moose likes Beginning Java and the fly likes question about maths class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "question about maths class" Watch "question about maths class" New topic
Author

question about maths class

Kartik Mahadevan
Ranch Hand

Joined: Feb 16, 2005
Posts: 47
Hi
Why r we not able to make statements like

Maths a = new Maths();

I assume that constructors r private but is there a way in which we can access them.

Regards
Kartik
Thomas Paul Bigbee
Ranch Hand

Joined: Jun 28, 2005
Posts: 71
The math class cannot be instantiated, it consists of a bunch of static methods
Kartik Mahadevan
Ranch Hand

Joined: Feb 16, 2005
Posts: 47
Hi
but is it necessary that classes which have a bunch of static methods cannot be initialized.

Regards
M.Kartik
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

The java.lang.Math class has no public constructors, deliberately, simply because it would make no sense to have a java.lang.Math object. There are some other classes like this: java.lang.System is one.

Why do you want to do this?


[Jess in Action][AskingGoodQuestions]
Kartik Mahadevan
Ranch Hand

Joined: Feb 16, 2005
Posts: 47
Sir
I just wanted to check that if i make a class and make it's constuctors private nobody could make objects of that class.

Thanks
Kartik
Megs Maquito
Ranch Hand

Joined: May 18, 2005
Posts: 84
i think another advantage of a class having a private constructor and static methods is, it saves memory as it doesn't go on the heap.


I'm a Hood Ornament
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
I just wanted to check that if i make a class and make it's constuctors private nobody could make objects of that class


You can do that by just creating such a class of your own, and simple checking if it is possible, no?


Ping & DNS - my free Android networking tools app
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: question about maths class