• 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

static method to call from other package

 
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,
would you be able to show me how static method call non-static method in same class?

I tried to put a simple of my two program below.

please show me how to fix this problem.

Regards,

e.g

package pgm;
import pgm.*;

class A;

public static Map getValues(String ISBN_digit) {
Hashtable ht = new Hashtable();
String message = "from CCHKDigit() ";
Boolean IN60 = new Boolean(true);

CHKISBN(String ISBN_digit) // my problem is in this method???

ht.put("msg", message);
ht.put("error", IN60);

return ht;
}

public char CHKISBN(String isbn10) {

PXERCD = '0';
isbn10 = isbn10.toUpperCase().trim();
char[] theChars = isbn10.toCharArray();

//int val=0;
StringBuffer sb = new StringBuffer();

// 2. validation of input ISBN code's chacters
F = 10;
RUNTOT=0;
for (int X = 0; X<=9; X++) {

if (X < 9) {
RUNTOT += F * Character.getNumericValue(theChars[X]);
F--;
}
//System.out.println("theChars[X]"+theChars[X]);
int val =NUMVALUES.indexOf(theChars[X]);
//System.out.println("INDEXOF-VAL:"+ val);
if(val == -1) {
PXERCD = '2';
System.out.println("pxercd"+PXERCD);
return PXERCD;
}//end of if
}//end of for


XCHECK = Character.getNumericValue(theChars[isbn10.length() - 1]);
XXREST = (int)((long)(RUNTOT)%(long)(11));

if (XXREST == 0) {
XXCHKD = 0;
}else if(XXREST == 1) {
XCCHKD = 'X';
XXCHKD = 1;
}else{
XXCHKD = (11 - XXREST);
}
// Check if error
if (Character.getNumericValue(isbn10.charAt(9)) != XXCHKD && XXREST !=1) {
PXERCD = '1';
}else if(isbn10.charAt(9) != XCCHKD && XXREST ==1) {
PXERCD = '1';
}else {
PXERCD = '0';
} //�end if-else

return PXERCD;

}//end of method of CHKISDN


package pgm;
class b{
public void checkDigits(String ITNO) {

ItemNo = ITNO;
Hashtable rValues = (Hashtable) CCHKDigit.getValues(ITNO);
String msg = (String) rValues.get("msg");
boolean error = ((Boolean)(rValues.get("error")) ).booleanValue();

System.out.println("Error" + error);
System.out.println("Message" + msg);
}
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A static method in a class definition cannot directly access the instance methods. The instance methods only have meaning when you create an instance of the class.
 
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
thank, Keith,
Do you have any example source to get multiple return values from other class with instance method in instance of the class?

thanks,
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry, but I don't understand your question.

I don't see where you're trying to call an instance method in another class.

A method can't have multiple return types.

However, if you want to return multiple values, you can encapsulate them into an object.
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic