• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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: 63470
207
  • 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: 21649
101
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!
 
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!