Java Quiz

0 votes, 0 avg
382

Java Questions

1 / 15

1. Which of these is returned by “greater than”, “less than” and “equal to” operators?

2 / 15

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

            }

       }

3 / 15

3. Which of the following is a type of polymorphism in Java?

4 / 15

4. Which of these is necessary condition for automatic type conversion in Java?

5 / 15

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

            }

       }

6 / 15

6. Identify the modifier which cannot be used for constructor.

7 / 15

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

            }

        }

8 / 15

8. Find the output of the following program.

public class Solution{
       public static void main(String[] args){
                     byte x = 127;
                     x++;
                     x++;
                     System.out.print(x);
       }
}

9 / 15

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

10 / 15

10. Which environment variable is used to set the java path?

11 / 15

11. File class is included in which package?

12 / 15

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

13 / 15

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

class Char {
public static void main(String args[]) {
char ch1, ch2;
ch1 = 88; // code for X
ch2 = 'Y';
System.out.print("ch1 and ch2: ");
System.out.println(ch1 + " " + ch2);
}
} 

14 / 15

14. Find the output of the following code.

        class output 

        {

            public static void main(String args[])

            { 

               StringBuffer s1 = new StringBuffer("Quiz");

               StringBuffer s2 = s1.reverse();

               System.out.println(s2);

            }

        }

15 / 15

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

        class static_out 

        {

            static int x;

     	static int y;

            void add(int a, int b)

            {

                x = a + b;

                y = x + b;

            }

        }    

        public class static_use 

        {

            public static void main(String args[])

            {

                static_out obj1 = new static_out();

                static_out obj2 = new static_out();   

                int a = 2;

                obj1.add(a, a + 1);

                obj2.add(5, a);

                System.out.println(obj1.x + " " + obj2.y);     

            }

       }

Your score is

The average score is 35%

0%

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