Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class question...

 
Conrad Kirby
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Conrad Kirby
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only stupid question is the one you don't ask!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic