Function overloading

Posted by Unknown at 19:00

class exam
{
        private int m1,m2,total;
        public void setmarks(int ma1,int ma2)
        {
                m1 = ma1;
                m2 = ma2;     
        }
        public void setmarks()
        {
                m1 = 80;
                m2 = 100;
        }
        void calculate()
        {
                total = m1 + m2;
        }
        void disp()
        {
                System.out.println("Mark1 : " + m1 + "\t Mark2 " + m2 + "\t Total " + total);
        }
        public static void main(String args[])
        {
                exam e1 = new exam();
                exam e2 = new exam();
                e1.setmarks();
                e2.setmarks(70,80);
                e1.calculate();
                e2.calculate();
                e1.disp();
                e2.disp();
        }
}


If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

0 comments:

Have any question? Feel Free To Post Below:

 

© 2011. All Rights Reserved | Interview Questions | Template by Blogger Widgets

Home | About | Top