In: Computer Science
public class Main{
public static void main(String args[]){
//create array of Contact object
Contact[] obj = new Contact[2] ;
//create actual Contact object
obj[0] = new Contact();
obj[1] = new Contact();
//assign data to Contact objects
obj[0].setData(1008795,"era","[email protected]");
obj[1].setData(2056840,"XYZ","[email protected]");
//display the Contact object data
System.out.println(" Contact Object 1:");
obj[0].showData();
System.out.println(" Contact Object 2:");
obj[1].showData();
}
}
//Contact class with phone,email and name as attributes
public class Contact{
int phone;
String name;
String email;
public void setData(int phone,String name,String
email){
int this. phone=phone;
String this.name=name;
String this. email=email;
}
public
int
getphone()
{
return
this
.phone;
}
public
void
setphone(
int
phone) {
this
.phone
= phone;
}
public
String
getName()
{
return
this
.name;
}
public
void
setName(
int
name)
{
this
.name=
name;
}
public
String
getEmail()
{
return
this
.email;
}
public
void
setEmail(
int
email) {
this
.email=email;
}
public void showData(){
System.out.print("phone = "+phone +
" " + " Name = "+name+" email = "+email);
System.out.println();
}
}