*
The moose likes Beginning Java and the fly likes array of object to call a method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "array of object to call a method" Watch "array of object to call a method" New topic
Author

array of object to call a method

shribalaji arumugham
Greenhorn

Joined: Jul 20, 2008
Posts: 3
an serious doubt how to call a method using array of objects?
here class bank have b1[] as a array of object... i need to call method get() for two objects b1[0].get()? it showing error....[edit]Add code tags and sort out indentation. CR[/edit]
[ July 20, 2008: Message edited by: Campbell Ritchie ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

Welcome to JavaRanch!

In the following code:

bank[] b1 = new bank[2];
bank[0]=new b1.get();

Which class is "get" a member of, and why is there a "new" on the second line -- what class are you trying to create an instance of?

Are you trying to create an array with two "bank" objects in it? That would look like

bank[] b1 = new bank[2]; // Create an empty array with room for two "bank" objects
bank[0] = new bank(); // Put a new "bank" into the first space in the array
bank[1] = new bank(); // and another in the second

When you write lines lines like this:

b1[0].cal(a);
b1[0].dis(a);

These lines show the correct way to call methods in the class "bank" named "cal" and "dis", each of which accepts an "int" parameter. Is this what you're trying to do?


[Jess in Action][AskingGoodQuestions]
shribalaji arumugham
Greenhorn

Joined: Jul 20, 2008
Posts: 3

here what im trying to do is i want to more than 1 account to maintain, i.e i want to create 2 objects to hold each record b1[0],b1[1] to call get()method and cal()method disp() methods :roll:

[edit]Add code tags, tiny spelling correction. CR[/edit]
[ July 20, 2008: Message edited by: Campbell Ritchie ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array of object to call a method
 
Similar Threads
array question?
Why my Array skips the first entry ?
Need help with username and password validation
Once more about Array
Getting value of all the indices of all objects from an arraylist