• 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

array of object to call a method

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic