• 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

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

 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you tell with an example. How to make the changes.?
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A sample code to call a method from the main.

Read more on this tutorial.
 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Jai wrote:A sample code to call a method from the main.

Read more on this tutorial.




Thank you... John Jai.
 
Nothing up my sleeve ... and ... presto! A tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic