• 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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: 61691
193
  • 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: 21463
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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!