Hi Hhb Bhh
All the code belongs to a class in Java (unlike C++ for e.g.). Static
code belongs to "static" methods in Java (is not outside classes). In
particular, the command line "java foo" executes the static method
called "main" of the class "foo.class" (obtained by compiling "foo.java").
If I truly understand your problem, you have written the code to execute
and test the class outside any class.
It should work like this:
public class MyOwnClass {
private String name;
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
* _public static void main( String[] args ) {_*
* ArrayList al = new ArrayList();*
* MyOwnClass obj = new MyOwnClass();*
* al.addAll(Arrays.asList(n));*
* al.add(new Integer(1));*
* al.add(obj);*
* System.out.print("The arrayList of al: ");*
* for (Iterator it = al.iterator(); it.hasNext(); ) {*
* Object element = it.next();*
* System.out.println(element);*
* }*
* }*
} // Nothing below this line
///////////////////
or something in this style.
Hope it helps
Mihai
Le 29/09/2010 09:33, hhb bhh a écrit :
hello,
# 2 MyOwnClass object (You will have to create MyOwnClass.java first)
* MyOwnClass class has name (String type) and age (int type) is
the requirement is create an class and add the class for example into
arrayList ??
I try
public class MyOwnClass {
private String name;
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
///////////////////
ArrayList al = new ArrayList();
al.addAll(Arrays.asList(n));
al.add(new Integer(1));
al.add(obj);
System.out.print("The arrayList of al: ");
for (Iterator it = al.iterator(); it.hasNext(); ) {
Object element = it.next();
System.out.println(element);
}
I get mycollectionproject.myowncl...@10385c1
what is wrong???
--
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