• 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

Calling method from another class

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to call a method(with arguments) from another class without inherinting that class
 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by shalini gnana:
How to call a method(with arguments) from another class without inherinting that class



If both the class reside in current working directory then you can directly create an object of that class and call its methods using that object.
Otherwise in shell prompt you can use -classpath option of java to get that class.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need a reference to an object of the other class. Your class could get that either as a parameter in its constructor, construct a new instance of it, or get a reference through a setter method like below. Of course, setTheOtherObject must be called before myMethod can run.


[ January 03, 2008: Message edited by: Ulf Dittmer ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic