Saturday 28 July 2012

Passing object as arguments.


class rectangle
{
        private int len,bre;
        public void setrect(int l,int b)
        {
                len = l;
                bre = b;
        }
        public int totlen(rectangle t)
        {
                return len + t.len;
        }
        public int totbre(rectangle t)
        {
                return bre + t.bre;
        }
        rectangle combine(rectangle t)
        {
                rectangle temp = new rectangle();
                temp.len = len + t.len;
                temp.bre = bre + t.bre;
                return temp;
        }
        public void disp()
        {
                System.out.println("Length : " + len + "\t Breadth : " + bre);
        }
        public static void main(String args[])
        {
                rectangle r1 = new rectangle();
                rectangle r2 = new rectangle();
                rectangle r3 = new rectangle();
                r1.setrect(2,3);
                r2.setrect(4,5);
                int tlen = r1.totlen(r2);
                int tbre = r1.totbre(r2);
                r3 = r1.combine(r2);
                System.out.println("Total length : " + tlen);
                System.out.println("Total Breadth : " + tbre);
                r1.disp();
                r2.disp();
                r3.disp();
        }
}

16 comments:

  1. Your new valuable key points imply much a person like me and extremely more to my office workers. With thanks from every one of us.

    Best AWS Training in Chennai | Amazon Web Services Training in Chennai

    ReplyDelete
  2. I really like your blog. You make it interesting to read and entertaining at the same time. I cant wait to read more from you.
    Java training in Chennai | Java training in Bangalore

    Java interview questions and answers | Core Java interview questions and answers

    ReplyDelete
  3. Awesome! Education is the extreme motivation that open the new doors of data and material. So we always need to study around the things and the new part of educations with that we are not mindful.
    Data Science course in rajaji nagar | Data Science with Python course in chenni

    Data Science course in electronic city | Data Science course in USA

    Data science course in pune | Data science course in kalyan nagar

    ReplyDelete
  4. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    Devops Training in Chennai | Devops Training Institute in Chennai

    ReplyDelete
  5. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command
    Microsoft Azure online training
    Selenium online training
    Java online training
    Python online training
    uipath online training

    ReplyDelete
  6. Your article is very helpful.You can visit my website :zedge application

    ReplyDelete
  7. keep sharing your information regularly for my future reference. This content creates a new hope and inspiration with me.
    AWS training in chennai | AWS training in anna nagar | AWS training in omr | AWS training in porur | AWS training in tambaram | AWS training in velachery

    ReplyDelete
  8. Visit ETRADE LOG ON Login To View Your Personal Area Where You Can Manage Your Trading Accounts, Set Up Your Watchlist, And Track Your Recent Trades.

    ReplyDelete