how to use two different class in same program during run time?
deepika deepi
Ranch Hand
Joined: Jan 23, 2012
Posts: 199
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
can you tell with an example. How to make the changes.?