Beruflich Dokumente
Kultur Dokumente
Instatntiation Class:
//declaring attributes
private int id;
private String name;
private String branch;
//constructor
public Student(int id, String name, String branch)
{
this.id = id;
this.name = name;
this.branch = branch;
}
So, first class is done. As you are doing in eclipse…. Just declare the attributes. In the toolbar
source”Generate getters and setters” (select all) and again “Generate Constructor using fields”
S[0]=new Student(1,”teju”,”ECE”);
S[1]=new Student(2,”moh”,”CSE”);
S[2]=new Student(3,”test”,”CSE”);
Declare the method with with proper return type and specified attributes.
Here the method is with array of student attribute and the return type is Student
S[0]=new Student(1,”teju”,”ECE”);
S[1]=new Student(2,”moh”,”CSE”);
S[2]=new Student(3,”test”,”CSE”);
Student stu= findById(s,3);
System.out.println(stu.getId());
System.out.println(stu.getName());
System.out.println(stu.getBranch());
For(i=0;i<stud.length;i++)
If(stud[i].getId()==id)
return st;
.Don’t write stud.getId because stud is array of objects ; not a single object
As return type is student we need to return that particular object which matches the id