Monday, 5 September 2011

Class Demo in java

class Testing
{
    private int x;

    public void setX (int x) // setter method
    {
        this.x = x;
    }
   
    public int getX()  // getter method
    {
        return this.x;
    }
}



public class TestingMain
{
    public static void main(String[] args)
    {
        Testing testing = new Testing();

            testing.setX(100);
           
        int x = testing.getX();
       
       
        System.out.println("X is : "  + x);
           
       
        System.out.println("X is : " + testing.getX());
       
       
       
       
    }
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.