Hello I am a little confused. I had always thought that a class can have objects from other clases as attributes. My teacher recently told me that this is not true... so I am confused now: if one of the attributes of my class is a String, would that be an object inside my class???? Teacher says it's simply a variable...
G_S
38
Junior Poster in Training
Recommended Answers
Jump to Postthe class itself is not a member of that other class, but an instance of it is.
not entirely sure what your question is, or what your teacher said, but sure, if you create a class
MyClassA, you can have another class with a MyClassA as either instance or static …
Jump to PostI don't understand what point your teacher is trying to make.
The Java Language Spec doesn't use the term "attribute" except in two places. One is a very technical discussion of garbage collection, and the other uses it to mean a variable that can be accessed via get/set methods. So …
Jump to PostEven so, the teacher is also correct when he says that a field is simply a variable. After all, in most practical ways a field is like a local variable that happens to have a longer life and larger scope. Perhaps the teacher is trying to make a clear distinction …
Jump to Postif one of the attributes of my class is a String, would that be an object inside my class???? Teacher says it's simply a variable...
There is no String inside your object. Keeping aside primitives for the time being, if a class is composed of multiple fields having …
All 13 Replies
stultuske
1,116
Posting Maven
Featured Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
bguild
163
Posting Whiz
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
G_S
38
Junior Poster in Training
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
mvmalderen
2,072
Postaholic
G_S
38
Junior Poster in Training
stultuske
1,116
Posting Maven
Featured Poster
mvmalderen
commented:
You make a good point about "A main method" versus "THE main method(s)".
+0
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
mvmalderen
commented:
Yaay, JLS! :)
+13
G_S
38
Junior Poster in Training
stultuske
1,116
Posting Maven
Featured Poster
G_S
38
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.