Student.java:
public class Student{
int stdid;
String name;
private int x=3;
public Student(int stdid, String name){
this.stdid = stdid;
this.name = name;
}
public String toString(){
return name + ": " + stdid;
}
public static void main(String args[]){
Student x = new Student(123, "azin");
System.out.println(x);
University u = new University();
u.addStudent(x);
u.addStudent(x);
u.addStudent(x);
u.print();
}
// public void setX(int x) {
// this.x = x;
// }
public int getX() {
return x;
}
}
University.java:
import java.util.Vector;
public class University{
Vector
public void addStudent(Student s){
students.add(s);
}
public void print(){
//foreach
for (Student s: students){
System.out.println(s);
System.out.println(s.getX());
}
}
}
هیچ نظری موجود نیست:
ارسال یک نظر