Results 1 to 4 of 4
- 01-04-2012, 01:58 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 12
- Rep Power
- 0
Creating an object containing an array and int - small error
Hi,
I am writing a black jack program and have created an object containing an array if ints (the players hand) and one other int value (the dealers faced up card). But when i try to create an instance of the object, i seem to be declaring it wrong. Here is my code. on the last line 'hand []' is underlined showing 'The type of the expression must be an array type but it resolved to CreateHand'
public class CreateHand {
int cardA = 0;
int cardB = 0;
int dealersCard;
int [] hand = {cardA, cardB};
public CreateHand(int [] hand1, int dCard){
hand = hand1;
dealersCard = dCard;
}
public CreateHand Start(){
CreateHand hand = new CreateHand(hand [],dealersCard); // hand [] has a syntax error!
code continues .......
iv tired 'hand' , '[] hand' and 'hand[]'..... any ideas where i am going wrong?
Many Thanks
- 01-04-2012, 02:01 PM #2
Re: Creating an object containing an array and int - small error
You don't use the type of a variable when using that variable as an argument to a method. Just use the name of the variable: hand
leave off the []s
- 01-04-2012, 02:25 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 12
- Rep Power
- 0
Re: Creating an object containing an array and int - small error
thanks for that. I tried 'hand' on its own but it still didn't like it. I played around with it a bit and found that the object was also called 'hand' and they couldn't be the called the same name.
Thanks for your help
- 01-04-2012, 02:30 PM #4
Similar Threads
-
Creating and implementing class for creating a calendar object
By kumalh in forum New To JavaReplies: 9Last Post: 07-29-2011, 02:18 PM -
Trouble creating object that includes array
By Desdenova in forum New To JavaReplies: 7Last Post: 05-18-2010, 07:33 PM -
small error
By ayoood in forum New To JavaReplies: 23Last Post: 05-27-2008, 12:18 PM -
Need help with creating array of type object
By riz618 in forum New To JavaReplies: 3Last Post: 01-29-2008, 06:14 AM -
Creating object of Type Object class
By venkatv in forum New To JavaReplies: 3Last Post: 07-17-2007, 03:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks