aspose file tools*
The moose likes Beginning Java and the fly likes Testing a constructor.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Testing a constructor...." Watch "Testing a constructor...." New topic
Author

Testing a constructor....

Oscar E Rodriguez
Greenhorn

Joined: Dec 12, 2008
Posts: 22
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

Joined: Oct 13, 2005
Posts: 39409
    
  28
new A();
Oscar E Rodriguez
Greenhorn

Joined: Dec 12, 2008
Posts: 22
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

Joined: Oct 27, 2005
Posts: 19720
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Oscar E Rodriguez
Greenhorn

Joined: Dec 12, 2008
Posts: 22
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Testing a constructor....