Java Quiz

0 votes, 0 avg
398

Java Questions

1 / 15

1. 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);

            }

       }

2 / 15

2. How to sort an array?

3 / 15

3. Which of these can be used to differentiate two or more methods having the same name?

4 / 15

4. What is the process of defining two or more methods within same class that have same name but different parameters declaration?

5 / 15

5. File class is included in which package?

6 / 15

6. 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));

            }

        }

7 / 15

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

8 / 15

8. 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);

            } 

        }

9 / 15

9. 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() + " ");

            }

        }

10 / 15

10. Find the output of the following program.

public class Solution{
       public static void main(String[] args){
                     short x = 10;
                     x =  x * 5;
                     System.out.print(x);
       }
}

11 / 15

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

        class recursion 

        {

            int fact(int n) 

            {

                int result;

                if (n == 1)

                    return 1;

                result = fact(n - 1) * n;

                return result;

            }

        } 

        class Output 

        {

            public static void main(String args[]) 

            {

                recursion obj = new recursion() ;

                System.out.print(obj.fact(5));

            }

        }

12 / 15

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

13 / 15

13. What is the default value of String variable?

14 / 15

14. Which of these is correct about passing an argument by call-by-value process?

15 / 15

15. What is true about final class?

Your score is

The average score is 35%

0%

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top