This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See thanks.
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • 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?
Posts: 7023
  • Mark post as helpful
  • send pies
  • 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.
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!