0% found this document useful (0 votes)
7 views

To String Method

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

To String Method

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

package setterGetter;

public class Student {

private int rollno;

private String name;

private String address;

public int getRollno() {


return rollno;
}

public void setRollno(int rollno) {


this.rollno = rollno;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public String getAddress() {


return address;
}

public void setAddress(String address) {


this.address = address;
}

public void display() {


System.out.println(rollno + " " + name + " " + address);
}

public static void main(String[] args) {


Student stu = new Student();
stu.setRollno(11);
stu.setName("Santosh");
stu.setAddress("PUne");

stu.display();

Student stu1 = new Student();


stu1.setRollno(22);
stu1.setName("Ganesh");
stu1.setAddress("Beed");

stu1.display();
}

2)
package setterGetter;

public class Student {

private int rollno;

private String name;

private String address;

public int getRollno() {


return rollno;
}

public void setRollno(int rollno) {


this.rollno = rollno;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public String getAddress() {


return address;
}

public void setAddress(String address) {


this.address = address;
}

public String display() {


return rollno + " " + name + " " + address;
}

public static void main(String[] args) {


Student stu = new Student();
stu.setRollno(11);
stu.setName("Santosh");
stu.setAddress("PUne");

System.out.println(stu.display());

Student stu1 = new Student();


stu1.setRollno(22);
stu1.setName("Ganesh");
stu1.setAddress("Beed");

System.out.println(stu1.display());
}

3)
package setterGetter;

public class Student {

private int rollno;

private String name;

private String address;

public int getRollno() {


return rollno;
}

public void setRollno(int rollno) {


this.rollno = rollno;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public String getAddress() {


return address;
}

public void setAddress(String address) {


this.address = address;
}

@Override
public String toString() {
return "Student [rollno=" + rollno + ", name=" + name + ", address=" +
address + "]";
}

public static void main(String[] args) {


Student stu = new Student();
stu.setRollno(11);
stu.setName("Santosh");
stu.setAddress("PUne");

System.out.println(stu.toString());

Student stu1 = new Student();


stu1.setRollno(22);
stu1.setName("Ganesh");
stu1.setAddress("Beed");

System.out.println(stu1.toString());
}

}
4)

package setterGetter;

public class Student {

private int rollno;

private String name;

private String address;

public int getRollno() {


return rollno;
}

public void setRollno(int rollno) {


this.rollno = rollno;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public String getAddress() {


return address;
}

public void setAddress(String address) {


this.address = address;
}

@Override
public String toString() {
return "Student [rollno=" + rollno + ", name=" + name + ", address=" +
address + "]";
}

public static void main(String[] args) {


Student stu = new Student();
stu.setRollno(11);
stu.setName("Santosh");
stu.setAddress("PUne");

System.out.println(stu);

Student stu1 = new Student();


stu1.setRollno(22);
stu1.setName("Ganesh");
stu1.setAddress("Beed");

System.out.println(stu1);
}

You might also like