This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "array" Watch "array" New topic
Author

array

jp staff
Greenhorn

Joined: Sep 10, 2001
Posts: 5
How do I make An array if I want to make an instance of a class, in other words
class BB{
private int n;
public calculations();
}
\\\\\\\\Here is the main driver
How can I set up an array of 25 b classes, would it be
BB bk[]=new BB[25]
How would I beable to access each method from the main:
bk[i].calculations();
Thanks for your help
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You have to instantiate each of your array elements if you will be using them.
for(int i = 0; i< bk.length; i++)
bk[i] = new (What ever yoeu constructor is expecting)
}
bk[i].calculations();
Bosun




Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
GeeCON Prague 2014
 
subject: array