using .class file in java

N

neha

i have BankAPIClient.class file and now want to use it in another
program CallBankAPIClient.java by instantiating an object of above
class file. How to do it? guide me.....

Regards,
Neha Gupta
 
R

Rhino

neha said:
i have BankAPIClient.class file and now want to use it in another
program CallBankAPIClient.java by instantiating an object of above
class file. How to do it? guide me.....
Add a line like this one to your CallBankAPIClient class:

BankAPIClient myBankAPIClient = new BankAPIClient();

Naturally, you need to pass any arguments required by the BankAPIClient
constructor too. For example:

BankAPIClient myBankAPIClient = new BankAPIClient(customerName,
accountNumber);

Then, to use the methods of the new instance, imitate this:

myBankAPIClient.setPhoneNumber("123-3456");
 
C

Camilla

i have BankAPIClient.class file and now want to use it in another
program CallBankAPIClient.java by instantiating an object of above
class file. How to do it? guide me.....

Regards,
Neha Gupta

Hi! try something like this:

import package.BankAPIClient;

public CallBankApiClient{

// object BankAPIClient
BankAPIClient bap;

public static void main(String[] args){
//initialize object
bap=new BankAPIClient();

//use Object's methods
bap.method();

}
}

you can do this in the main if you're using this as a test class, and
in all of your methods, assuming that BankAPIClass is declared as
public in its package
ciao, Camilla
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top