This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Testing a constructor....

 
Oscar E Rodriguez
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following class in a package:

and I am tring to define a constructor for class A that print out the words "Here we go".
SO I did this:


It compiled without errors....but how do I check it (or exectue it) to see if I did it right?

Any feedback would be greatly appreciated.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49457
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
new A();
 
Oscar E Rodriguez
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:
new A();


Thank you Campbell....
so I tried your suggestions:


it compiles without errors.
But then when I type "java A" in my command window I get the following error:
Exception in thread "main" java.lang.NoSuchMethodError: main

where am I missing the point?

Thank you for ALL your help.
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to add a main method:

You should also remove the "new A()" from your "f()" method - it will create a new A object every time you call the method. And after that the object is discarded again.
 
Oscar E Rodriguez
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
You need to add a main method:

You should also remove the "new A()" from your "f()" method - it will create a new A object every time you call the method. And after that the object is discarded again.


Thank you Rob!
Worked beautifully!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic