Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array of object to call a method

 
shribalaji arumugham
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
shribalaji arumugham
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic