Java Quiz

0 votes, 0 avg
353

Java Questions

1 / 15

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

        class A 

        {

            public int i;

            protected int j;

        }    

        class B extends A 

        {

            int j;

            void display() 

            {

                super.j = 3;

                System.out.println(i + " " + j);

            }

        }    

        class Output 

        {

            public static void main(String args[])

            {

                B obj = new B();

                obj.i=1;

                obj.j=2;   

                obj.display();     

            }

       }

2 / 15

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

        class output 

        {

            public static void main(String args[])

            {

                String a = "hello i love java";

                System.out.println(a.indexOf('i')+" "+a.indexOf('o') +" "+a.lastIndexOf('i')+" "+a.lastIndexOf('o'));

            }

        }

3 / 15

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

            }

       }

4 / 15

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

            }

        }

5 / 15

5. Find the output of the following program.

class output {
public static void main(String args[]) 
            {
                double a, b,c;
                a = 3.0/0;
                b = 0/4.0;
                c=0/0.0;
    	    System.out.println(a);              System.out.println(b);               System.out.println(c);
            } 
        }

6 / 15

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

7 / 15

7. What is the default value of String variable?

8 / 15

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

        class recursion 

{

int func (int n)

{

int result;

if (n == 1)

return 1;

result = func (n - 1);

return result;

}

}

class Output

{

public static void main(String args[])

{

recursion obj = new recursion() ;

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

}

}


                            

9 / 15

9. Which of these data types is used to store command line arguments?

10 / 15

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

11 / 15

11. What is Recursion in Java?

12 / 15

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

13 / 15

13. What is the value returned by function compareTo() if the invoking string is less than the string compared?

14 / 15

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

        class Output 

        {

            public static void main(String args[])

            {

                int arr[] = {1, 2, 3, 4, 5};

                for ( int i = 0; i < arr.length - 2; ++i)

                    System.out.println(arr[i] + " ");

            } 

        }

15 / 15

15. 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++;

                }

            } 

        }

Your score is

The average score is 36%

0%