• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between a variable and data member

 
Vallabhaneni Suresh Kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai.
I am a beginner in Java. Is there any difference between a variable and a data member? If so what are the differences?
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is "Data Member"? Are you talking about the Attribute of a class?

These are different Variable can be of Class Level or Method level but Attribute of a class is class level.
 
Elouise Kivineva
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A variable is something referred to by a reference, such as int age (an integer named age). You can set a variable's value and reset it if the variable is not declared to be final. Declaring a final variable daysInAWeek = 7 makes for clearer code than just using the numer 7. A variable can be a primitive or an object reference.

Member data is/are variable(s) that belong to an object. A cat object for instance could have member data such as a string color and int age. Each cat object can then store, maintain and provide upon request its own information regarding its color and age.

See also Cup Size, a story about variables: http://www.javaranch.com/campfire/StoryCups.jsp
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic