Creating new instance
class MyDetails
{
public static void main(String[] args)
{
//Creating an instance of Details class
Details info1=new Details();
Details info2=new Details();
//Name and age passed to methods of first person
info1.setName("Padmini");
info1.setAge(20);
info1.print();
//Name and age passed to methods of second person
info2.setName("Manjunath");
info2.setAge(25);
info2.print();
}
}
Here above, cant we use the same instance info1 instead of info2 for calling method setAge and print to display second person details? I checked it,works fine, but does it make any differrence.