Java Quiz

0 votes, 0 avg
44

Java Questions

1 / 15

1. Which two classes use the Shape class correctly?

A. public class Circle implements Shape 
   {
    private int radius;
   }
B. public abstract class Circle extends Shape 
   {
    private int radius;
   }
C. public class Circle extends Shape 
   {
   private int radius;
   public void draw();
   }
D. public abstract class Circle implements Shape 
   {
    private int radius;
    public void draw();
   }
E. public class Circle extends Shape 
   {
    private int radius;
    public void draw()
    {
     /* code here */
    }
   }
F. public abstract class Circle implements Shape 
   {
     private int radius;
     public void draw() 
     { 
      /* code here */ 
     }
   }

2 / 15

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

                }

            } 

        }

3 / 15

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

            }

        }

4 / 15

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

5 / 15

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

    class abc

    {

        public static void main(String args[])

        {

            if(args.length>0)

            System.out.println(args.length);

        }

    }

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. Which of the following is not an OOPS concept in Java?

8 / 15

8. Which of these keywords are used for the block to be examined for exceptions?

9 / 15

9. What is true about final class?

10 / 15

10. Which of these is an incorrect array declaration?

11 / 15

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

            }

       }

12 / 15

12. How to format date from one form to another?

13 / 15

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

14 / 15

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

            } 

        }

15 / 15

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

Your score is

The average score is 30%

0%