Results 1 to 6 of 6
- 11-29-2008, 09:02 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 3
- Rep Power
- 0
whats wrong with this class declaration?
public class hashTable3 {
int[]anArray = new int[100];
for (int i = 0; i < anArray.length; i++)
anArray[i] = -1;
}
Hi,
why is the class declaration above faulty?
The way I read it is that "int[]anArray = new int[100];" creates an integer array called anArray
then for the loop statement the array exists so why does the loop not work?
i get "an illegal start of type errror...."
for
for (int i = 0; i < anArray.length; i++)
anArray[i] = -1;
very dazed and confused
- 11-29-2008, 09:38 PM #2
you should create the method for your stuff .
- 11-29-2008, 09:49 PM #3
Member
- Join Date
- Nov 2008
- Posts
- 3
- Rep Power
- 0
Do you mean a main method?
I will be calling this class from another test application which will have a main method. I do not need a main method in this class?
-
any method. you're trying to place code that needs to be within a method or constructor or static block outside of all of these things, and this is not kosher.
- 11-30-2008, 12:17 AM #5
Member
- Join Date
- Nov 2008
- Posts
- 3
- Rep Power
- 0
this is a class (below)i created before which compiles ok. I was using this as a template for the class that doesn't work, I dont really see the diference in construction between the two.
package labworkbook1;
public class ArrayStack {
int[] anArray= new int [5];
int top = 4;
int size = 5;
public int[] getArray(){
return anArray;
}
// method to check if the stack is full
public boolean isFull(){
return top==size-1;
}
//method to check if stack is empty
public boolean isEmpty (){
return top==-1;
}
// method to add (push) to the stack
public void push(int x)
{
if (isFull()) {System.out.println ("Stack is full");}
else
{
}
}
}Last edited by blossompark; 11-30-2008 at 12:18 AM. Reason: forgot to include code example
- 11-30-2008, 02:18 AM #6
You call the method, not the class
What Serjant means is that your class needs a method (like he said... any method). When you make a call to a class, you have to call a method in the class... you don't call the class itself. You can two one of two things:
- wrap a main method around your code and be able to execute the class' code directly or
- wrap other method around it and call that method from another class.
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Similar Threads
-
Whats wrong with my maths???
By soc86 in forum New To JavaReplies: 4Last Post: 11-03-2008, 05:52 PM -
whats my next step
By thirumurugan.sethu in forum New To JavaReplies: 4Last Post: 10-02-2008, 09:03 PM -
Whats next after core java
By nn12 in forum Advanced JavaReplies: 4Last Post: 09-23-2008, 01:07 PM -
Cannot understand whats wrong
By Lehane_9 in forum New To JavaReplies: 1Last Post: 03-06-2008, 07:57 PM -
Whats wrong with my code???
By Soda in forum New To JavaReplies: 2Last Post: 12-06-2007, 12:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks