Showing posts with label this. Show all posts
Showing posts with label this. Show all posts

Saturday, 28 July 2012

This Keyword Example 1


class load
  {
        String firstname;
        String lastname;
        int age;
        String profession;
       load assign(String firstname,String lastname,int age,String profession)
        {
                this.firstname = firstname;
                this.lastname = lastname;
                this.age = age;
                this.profession = profession;
                return this;
        }
        load assign(String fn,String ln)
        {
                firstname = fn;
                lastname = ln;
                return this;
        }
        load assign(String fn,String ln,String prof)
        {
                firstname = fn;
                lastname = ln;
                profession = prof;
                return this;
        }
        load assign(String fn,int ag)
        {
                firstname = fn;
                age = ag;
                return this;
        }
        void print()
        {
                System.out.println(firstname + " " + lastname + " " + age + " " + profession);
        }
        public static void main(String args[])
        {
                load fl = new load();
                fl.assign("Naveen","Kumar",23,"Programmer");
                fl.print();
                fl.assign("Raj","Prabhu");
                fl.print();
                fl.assign("Chitra","Devi","Analyst");
                fl.print();
                fl.assign("Nithya",34);
                fl.print();
        }
}

This Keyword example


class point
            {
        int x,y;
       void init(int x,int y)
        {
                this.x = x;
                this.y = y;
        }
        void display()
        {
                System.out.println("x = " + x);
                System.out.println("y = " + y);
        }
}
class point1
{
        public static void main(String args[])
        {
                point pp = new point();
                pp.init(4,3);
                pp.display();
        }
}