This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes how to use two different class in same program during run time? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to use two different class in same program during run time? " Watch "how to use two different class in same program during run time? " New topic
Author

how to use two different class in same program during run time?

deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
hi good morning. i have two different files first file is an printing statement and second file is an addition program. i want to get both the output's during run time. How to do that can any one help me ?



This is the code. i have put both the programs in same file. I am not sure how to use this. I am not getting any error in the coding. But the second Addition program is not printed. How to display both during run time?
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
deepika deepi wrote:I am not sure how to use this.... How to display both during run time?

You should see two .class files generated after you compile this Java file. Since both the classes have a main method, you can use the java command to run them. Note that you need to specify the class name after the java command to run the corresponding class.
deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
ya that is fine yaar. But the result to be displayed like this

Hello World!
Addition of two numbers!
Sum: 3

and i don't want to run by giving two different class file name.


John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Then call the method that does addition from the Test main. You can change the main() in AddNumbers class to something like add() and call it from Test's main.
deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
can you tell with an example. How to make the changes.?
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
A sample code to call a method from the main.

Read more on this tutorial.
deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
John Jai wrote:A sample code to call a method from the main.

Read more on this tutorial.



Thank you... John Jai.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use two different class in same program during run time?
 
Similar Threads
Java Rule Round-Up
Sum Of Digits
Error: Cannot find symbol during Importing package
How to turn a class into an executable file
getRuntime().exec()