Java Quiz

0 votes, 0 avg
440

Java Questions

1 / 15

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

            }

       }

2 / 15

2. Which of the following is true about public access modifier?

3 / 15

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

4 / 15

4. The concept of multiple inheritances is implemented in Java by

I. Extending two or more classes.
II. Extending one class and implementing one or more interfaces.
III. Implementing two or more interfaces.

5 / 15

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

6 / 15

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

            }

       }

7 / 15

7.  Which variables are created when an object is created with the use of the keyword 'new' and destroyed when the object is destroyed?

8 / 15

8. Find the output of the following code.

        class array_output 

        {

            public static void main(String args[]) 

            {

                int array_variable [] = new int[10];

    	    for (int i = 0; i < 10; ++i) 

                {

                    array_variable[i] = i;

                    System.out.print(array_variable[i] + " ");

                    i++;

                }

            } 

        }

9 / 15

9. Which exception is thrown when java is out of memory?

10 / 15

10. Find the output of the following code.

        class box 

        {

            int width;

            int height;

            int length;

        } 

        class main

        {

            public static void main(String args[]) 

            {        

                 box obj = new box();

                 obj.width = 10;

                 obj.height = 2;

                 obj.length = 10;

                 int y = obj.width * obj.height * obj.length; 

                 System.out.print(y);

            } 

        }

11 / 15

11. Identify the output of the following program.

String str = “Hellow”;
System.out.println(str.indexOf(‘t));

12 / 15

12. What is the syntax for java main method?

13 / 15

13. A method within a class is only accessible by classes that are defined within the same package as the class of the method. Which one of the following is used to enforce such restriction?

14 / 15

14. Which of these jump statements can skip processing the remainder of the code in its body for a particular iteration?

15 / 15

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

Your score is

The average score is 36%

0%

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

Scroll to Top