java exam

0 votes, 0 avg
398

Java Questions

1 / 15

1. From the following statements which is a disadvantage of an java array?

2 / 15

2. Which constructor creates an empty string buffer with the specified capacity as length.

3 / 15

3. Find the output of the following code.

        class bool_operator 

        {

            public static void main(String args[]) 

            {    

                 boolean a = true;

                 boolean b = !true;

                 boolean c = a | b;

     	     boolean d = a & b;

                 boolean e = d ? b : c;

                 System.out.println(d + " " + e);

            } 

        }

4 / 15

4. What will be the output of the following Java program?

        class String_demo 

        {

            public static void main(String args[])

            {

                int ascii[] = { 65, 66, 67, 68};

                String s = new String(ascii, 1, 3);

                System.out.println(s);

            }

       }

5 / 15

5. Find the output of the following code.

        import java.util.*;

        class Collection_iterators 

        {

            public static void main(String args[]) 

            {

                LinkedList list = new LinkedList();

                list.add(new Integer(2));

                list.add(new Integer(8));

                list.add(new Integer(5));

                list.add(new Integer(1));

                Iterator i = list.iterator();

                Collections.reverse(list);

    	    Collections.sort(list);

                while(i.hasNext())

    	        System.out.print(i.next() + " ");

            }

        }

6 / 15

6. What is not the use of “this” keyword in Java?

7 / 15

7. Which of these keywords is used to prevent content of a variable from being modified?

8 / 15

8. The following Syntax is used for?

class Subclass-name extends Superclass-name   {                     //methods and fields }

9 / 15

9. What is an assignment statement?

10 / 15

10. Find the output of the following code.

       class overload 

       {

            int x;

     	double y;

            void add(int a , int b) 

            {

                x = a + b;

            }

            void add(double c , double d)

            {

                y = c + d;

            }

            overload() 

            {

                this.x = 0;

                this.y = 0;

            }        

        }    

        class Overload_methods 

        {

            public static void main(String args[])

            {

                overload obj = new overload();   

                int a = 2;

                double b = 3.2;

                obj.add(a, a);

                obj.add(b, b);

                System.out.println(obj.x + " " + obj.y);     

            }

       }

11 / 15

11. What will be the output of the following Java code?

        class Output 

        {

            public static void main(String args[]) 

            {

                Integer i = new Integer(257);  

                byte x = i.byteValue();

                System.out.print(x);

            }

        }

12 / 15

12. What will be the output of the following Java program?

        class recursion 

        {

            int func (int n) 

            {

                int result;

                result = func (n - 1);

                return result;

            }

        } 

        class Output 

        {

            public static void main(String args[]) 

            {

                recursion obj = new recursion() ;

                System.out.print(obj.func(12));

            }

        }

13 / 15

13. What will be the output of the following Java code?

        class output 

        {

            public static void main(String args[])

            {

                 String chars[] = {"a", "b", "c", "a", "c"};

                 for (int i = 0; i < chars.length; ++i)

                     for (int j = i + 1; j < chars.length; ++j)

                         if(chars[i].compareTo(chars[j]) == 0)

                             System.out.print(chars[j]); 

            }

       }

14 / 15

14. Where does the system stores parameters and local variables whenever a method is invoked?

15 / 15

15. Which of these method of class String is used to remove leading and trailing whitespaces?

Your score is

The average score is 35%

0%

Scroll to Top