This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Testing a constructor....  RSS feed

 
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.
 
Marshal
Posts: 59783
188
  • 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.
 
Sheriff
Posts: 21424
94
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
Boost this thread!