Hello,
On 16 Nov., 03:45, "Agung Prasetyo" <[EMAIL PROTECTED]> wrote:
> Hi, the java master, i have the class like this :
> public class MyOwnClass
> {
> String name;
> int age;
>
> public MyOwnClass(String name,int age)
> {
> this.name = name;
> this.age = age;
> }
>
> }
>
> And i add this class instance object to the HashSet object --> s
> s.add(new MyOwnClass("Paris",19));
>
> when the s object is print using iterator, why the output show like this :
> [EMAIL PROTECTED]
>
Because this is the result of the toString()-Method of your MyOwnClass
instance.
Implement your own method to reply with the name and age.
> please help me ! i'm very confuse the following code.
> why when i add the object Integer ex : s.add(new Integer(8));
> why the output is 8
Because the API-Class Integer has the following method implemented:
public String toString() {
return String.valueOf(value);
}
HTH
Ewald
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---