Defining class and object

0 comments Posted by Unknown at 19:01

class students
{
        private int sno;
        private String sname;
        public void setstud(int no,String name)
        {
                sno = no;
                sname = name;
        }
        public void dispstud()
        {
                System.out.println("Student No : " + sno);
                System.out.println("Student Name :" + sname);
        }
        public static void main(String args[])
        {
                if(args.length < 2)
                {
                        System.out.println("Invalid Arguments");
                        System.exit(0);
                }
                students s = new students();
                int no = Integer.parseInt(args[0]);
                String name = args[1];
                s.setstud(no,name);
                s.dispstud();
        }
}
Read More »

Passing arguments and returning values.

0 comments Posted by Unknown at 19:01

Passing arguments and returning values.
class circle
{
        private int radius;
        public void setradius(int r)
        {
                radius = r;
        }
        public float calculate()
        {
                return 3.14f * radius * radius;
        }
        public static void main(String args[])
        {
                if (args.length < 1)
                {
                        System.out.println("Invalid Arguments");
                        System.exit(0);
                }
                circle c = new circle();
                c.setradius(Integer.parseInt(args[0]));
                float area = c.calculate();
                System.out.println("Radius : " + args[0]);
                System.out.println("Area : " + area);
        }
}
Read More »

Passing object as arguments.

1 comments Posted by Unknown at 19:01

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();
        }
}
Read More »

Function overloading

0 comments 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();
        }
}
Read More »

Static Variables and Methods

0 comments Posted by Unknown at 18:59

class Rect
{
        int length;
        int breadth;
        int area;
        static int count;
        Rect(int a,int b)
        {
                length = a;
                breadth = b;
                count++;
        }
        Rect()
        {
                length = 0;
                breadth = 0;
                count++;
        }
        void calc()
        {
                area = length * breadth;
        }
        void display()
        {
                System.out.println("Length : " + length);
                System.out.println("Breadth : " + breadth);
                System.out.println("Area : " + area);
        }
}
class Rect1
{
        public static void main(String args[])
        {
                System.out.println("No of object : " + Rect.count);
                Rect r1 = new Rect(10,20);
                r1.calc();
                System.out.println("No of object : " + Rect.count);
                Rect r2 = new Rect();
                r2.calc();
                System.out.println("No of object : " + Rect.count);
                r1.display();
                r2.display();
        }
}
Read More »

The Job Interview Phrase Book: The Things to Say to Get You the Job You Want

0 comments Posted by Unknown at 18:09

      • Author:  Nancy Schuman
      • File Size: 364 KB
      • Print Length: 258 pages
      • Page Numbers Source ISBN: 144050184X
      • Publisher: Adams Media (October 18, 2009)
      • Sold by: Amazon Digital Services, Inc.
      • Language: English
      • ASIN: B002SV379U
Read More »

Knockout Interview Answers (52 Brilliant Ideas)

0 comments Posted by Unknown at 17:40

    • Paperback: 272 pages
    • Publisher: Infinite Ideas; 2nd edition (March 1, 2007)
    • Language: English
    • ISBN-10: 1904902979
    • ISBN-13: 978-1904902973
    • Product Dimensions: 8.2 x 6.8 x 0.9 inches

Read More »
 

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

Home | About | Top