Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using Main ()

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any suggestions how I can pass these variables with assigned classes to my other object classes to evaluate? I am doing this to test my program that takes two inputs and compares whether their classes are similar or not.
Nothing I tried works.... So I feel I am misundertsanding how Main() works with other objects/classes:

Thanks.
[ June 24, 2002: Message edited by: nate saider ]
[ edited to re-format code -ds ]
[ June 24, 2002: Message edited by: Dirk Schreckmann ]
 
nate saider
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So far this is what I am assuming that I import in the object I want to test via

Does this have to be done if in the same package?
then within main(String[] args), I presume one simply says

if you are passing the variables to the constructor of that object and/or

if you are passing the variables to a method of said object.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't have to import classes in the same package as the class you are developing.
This class that has the ability to analyze the animal objects, does it have static methods that do the analyzing? If not, then perhaps you want to create an instance of the analyzing class in your Main class, and then invoke the proper method(s) of this instance of the analyzing class. An analyzing method could be developed to take the appropriate parameters and return the appropriate result.
You could also develop a constructor for the class to take the appropriate arguments upon construction.
Just remember, if you're instantiating a class, you can use the methods through the instance. Like this:not like this:unless the method is a static method.
Anything making any sense?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I feel I am misundertsanding how Main() works with other objects/classes
If you mean that you aren't clear how the main method works...
The main method of SomeClass is invoked by the JVM when you try to run a Java program like this:
java SomeClass
The main method is the entry point into the program - it's where the program begins execution. The main method should be public and static, return nothing (void), and accept a String array as its only parameter:
public static void main( String[] args )
Are we getting close to figuring out any of your questions yet?
 
Look! It's Leonardo da Vinci! And he brought a tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic