0% found this document useful (0 votes)
8 views2 pages

Setter Getter

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)
8 views2 pages

Setter Getter

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/ 2

1)

package setterGetter;

public class Student {

private int rollno;

private String name;

private String address;

public static void main(String[] args) {


Student stu = new Student();
stu.rollno = 11;
stu.name = "Santosh";
stu.address = "Pune";

System.out.println(stu.rollno);
System.out.println(stu.name);
System.out.println(stu.address);
}
}

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;
}
}

package setterGetter;

public class Test {

public static void main(String[] args) {


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

System.out.println(stu.getRollno());
System.out.println(stu.getName());
System.out.println(stu.getAddress());

Student stu1=new Student();


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

System.out.println(stu1.getRollno());
System.out.println(stu1.getName());
System.out.println(stu1.getAddress());

}
}

You might also like