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();
    Student  s2= new Student();
        Student  s3= new Student();       
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) { = name;

public int getPhone() {
return phone;

public void setPhone(int phone) { = phone;


    Program   Output  

How to set and get values using Java class . How to  set  and get  values  using Java class . Reviewed by Mukesh Jha on 11:04 PM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.