Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

call method from other class

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I would like to know how to call method from other class.

e.g A.class need to use B. public boolean CHECK(string aa)

thanks for reply ealier,
paul

[ May 03, 2007: Message edited by: Paul Maeng ]

(Nothing is urgent in this SCJP forum)
[ May 03, 2007: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Maeng:
Hi,
I would like to know how to call method from other class.

e.g A.class need to use B. public boolean CHECK(string aa)

thanks for reply ealier,
paul

[ May 03, 2007: Message edited by: Paul Maeng ]



Here it goes:
If both classes are in the same package;

 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In other words, unless the method is static, you will need a reference to an instance of B.
 
Eung maeng
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot, marc,
I did as you said and still get an error to recognise class B even same package.
I am not quite sure about making both class A,B in same package.

if you could explain to make them in same package, it would be working fine.

package pgm.test;

class A
...

Package pgm.test;

class B

look forward to reply from you again,

thanks
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you importing the package that has the calling method's class?

for eg.

In another file/package:
 
Eung maeng
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot, it's very clear to understand and very useful place.

/paul
 
New rule: no elephants at the chess tournament. Tiny ads are still okay.
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic