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

Class question...

Conrad Kirby
Ranch Hand

Joined: Jun 17, 2001
Posts: 178
I want to know if you can create use a static method of a class that has a constructor, but you haven't created an instance of that class. This may be a stupid question, but oh well: I'm a stupid person then.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Yes... you can call a static method of a class before any objects of it exist. That is why the preferred way of calling a static method is with the class name instead of the instance name...

As in...

... and many, many more.

Also, all classes have a constructor... if you do not supply one, Java gives you the default constructor with no parameters.

-Nate

P.S. - No question is a stupid question, as long as you learn from it... ( though why didn't you just try testing this out yourself... )
[This message has been edited by Nathan Pruett (edited June 19, 2001).]


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Conrad Kirby
Ranch Hand

Joined: Jun 17, 2001
Posts: 178
I was just confusing myself. I understood all along. I don't even know why I asked the question. What does a class having a constructor have anything to do with being able to call one of that class' static methods! I'm a dolt.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Conrad, Conrad, Conrad . . . (Cindy shakes head),
You KNOW what I'm going to say here. There ARE no stupid questions. Just think how many people who were secretly thinking the same thing that you have now help understand it better.
Why - You are practically a HERO !


"JavaRanch, where the deer and the Certified play" - David O'Meara
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
The only stupid question is the one you don't ask!!


Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class question...