ParaMetrize Method
Write at Class 1: under the variable
void setInformation( ) {
}
write at class 2:
teacher1.setInformation("King", "male", 19166666);
by replace of
teacher1.name = "King";
teacher1.gender ="Male";
teacher1.phone = 171000000;
Write at class 1:
void setInformation(String n,String g,int ph) {
name = n;
gender = n
;
phone = ph;
}
Now you can use void setInformation as long as you want to use
Class 1:
package oop;
public class Teacher {
String name, gender;
int phone;
void setInformation(String n,String g,int ph) {
name = n;
gender = g;
phone = ph;
}
void DisplayInformation () {
System.out.println("Name = "+name);
System.out.println("Gender = "+gender);
System.out.println("Phone Number = "+phone);
}
}
Class 2:
package oop;
public class test2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Teacher teacher1 = new Teacher(); // Create
Teacher teacher2= new Teacher();
teacher1.setInformation("King", "male", 19166666);
teacher1.DisplayInformation();
teacher2.setInformation("King Khan", "Male", 9199999);
teacher2.DisplayInformation();
}
}
Result:
Name = King
Gender = male
Phone Number = 19166666
Name = King Khan
Gender = Male
Phone Number = 9199999