This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Datatype and variables??

 
geetha nagarajan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does every java variable use a datatype?
I thought the answer was ,Yes:each variable must be declared with it's datatype.
But,acc.to the answer given,datatypes r optional.Pl.clarify.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give us the question in its context? Otherwise I agree with you. Every variable has an associated type. Even though, sometimes the type is not declared:
int[] array = new int[2];
The declared type of the variable array is int[]. However there are also two variables created.
array[0] and array[1] are variables with no names. In order to access them we use array access expressions. Both variables still have an associated type int, though such type was not declared. This is a subtlety anyway
 
geetha nagarajan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There was no specific context ,it was just a random question.Check out Question 4 in the below link.
http://chortle.ccsu.ctstateu.edu/cs151/Notes/chap08/chap08quiz.html
[ Corrected URL ]
[ May 31, 2002: Message edited by: Jessica Sant ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic