How to set and get values using Java class .
Here is an java example for setting the value and getting values from java class.
This code is vary simple but most useful class in most web based data driven applications.
It good to know about this class , vary simple just go through the code easy to understand.
public class SetGetStudent {
public static void main(String[] args) {
// TODO Auto-generated method stub
Student s1= new Student();
s1.setAge(20);
s1.setName("Muku");
s1.setPhone(22222);
Student s2= new Student();
s2.setAge(19);
s2.setName("biku");
s2.setPhone(33333);
Student s3= new Student();
s3.setAge(19);
s3.setName("tiku");
s3.setPhone(44444);
System.out.println("Age:"+ s3.getAge());
System.out.println("Name:"+ s3.getName());
System.out.println("Phone:"+ s3.getPhone());
}
}
class Student {
private int Age ;
private String name;
private int phone;
public int getAge() {
return Age;
}
public void setAge(int age) {
Age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPhone() {
return phone;
}
public void setPhone(int phone) {
this.phone = phone;
}
}
Program Output
----------------------------------------Age:19
Name:tiku
Phone:44444
How to set and get values using Java class .
Reviewed by Mukesh Jha
on
11:04 PM
Rating:
No comments:
Add your comment