• 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

member and attribute!!!

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i ran into the following codes and have some confusion.

Based on the above code, could you please help explain me the questions:
what is one member of the above program?
what is one attribute of the above program?
what's difference between member and attribute in OO?
thanks.
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I understand your question. Data Member == Attribute, Function Member == Method. So, the x variable in your class definition is a data member(attribute). Now, in the setter you pass in a parameter x. So to access the data member you need to qualify it with this. Otherwise the parameter x hides the data member. Is that what you were asking about?
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is one member of the above program?
what is one attribute of the above program?

(Ignoring compiler errors...)
Well, it's not really a program as the class doesn't have a proper main method.
The code describes what a Test object is. According to this code, a Test object has four members (one of which is a method) and three attributes (all ints).
what's difference between member and attribute in OO?
In Java, when one refers to an attribute, they are usually referring to a part of an object that defines the object's state (i.e. an instance variable). A static variable might be referred to as an attribute of the class in which it's defined.
Lots of things are members. Non-static methods and variables (declared outside of any method, constructor, or initialization block) are members of instances of the class in which they are defined. Static methods and variables are members of the class. Constructors are not members.
So, an attribute is a member, and a member might be an attribute or a method.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic