Java Quiz

0 votes, 0 avg
410

Java Questions

1 / 15

1. What is the process of defining a method in terms of itself, that is a method that calls itself?

2 / 15

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

            }

       }

3 / 15

3. What is garbage collection in the context of Java?

4 / 15

4. What is the syntax for java main method?

5 / 15

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

    class San

    {

     public void m1 (int i,float f)

     {

      System.out.println(" int float method");

     }

     

     public void m1(float f,int i);

      {

      System.out.println("float int method");

      }

     

      public static void main(String[]args)

      {

        San s=new San();

            s.m1(20,20);

      }

    }

6 / 15

6. 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?

7 / 15

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

8 / 15

8. Which of these statements is incorrect about Thread?

9 / 15

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

10 / 15

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

11 / 15

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

12 / 15

12. Find the output of the following code.

        class leftshift_operator 

        {

            public static void main(String args[]) 

            {        

                 byte x = 64;

                 int i;

                 byte y; 

                 i = x << 2;

                 y = (byte) (x << 2);

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

            } 

        }

13 / 15

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

14 / 15

14. Which of these keywords cannot be used for a class which has been declared final?

15 / 15

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

Your score is

The average score is 36%

0%

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

Scroll to Top