• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between a variable and data member

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic