Thursday 22 January 2015

Simple Encapsulation example in java

class test
{
  String Name=null;
  int age;
  String occupation=null;
  public void set(String name,int age1,String occ)
  {
      Name=name;
      age=age1;
      occupation=occ;
  }
  public void get()
  {
   
      System.out.println("-------YOUR PERSONAL INFORMATION------");
      System.out.println("NAME :"+Name);
      System.out.println("AGE :"+age);
      System.out.println("OCCUPATION :"+occupation);
     
  }

}
public class EncapsulationExample extends test{
    public static void main(String Dx[])
    {
        test t1=new test();
        t1.set("Dx Panchal",23,"TRAINEE");
        t1.get();
       
    }

}

No comments:

Post a Comment

How to change Background color by selecting color from Listview

activitymain.xml file::> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     xm...