Java Quiz

0 votes, 0 avg
376

Java Questions

1 / 15

1. Which of these method of class String is used to remove leading and trailing whitespaces?

2 / 15

2. What is the process of defining two or more methods within same class that have same name but different parameters declaration?

3 / 15

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

4 / 15

4. Find the output of the following code.

        class ternary_operator 

        {

            public static void main(String args[]) 

            {        

                 int x = 3;

                 int y = ~ x;

                 int z;

                 z = x > y ? x : y;

                 System.out.print(z);

            } 

        }

5 / 15

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

6 / 15

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

7 / 15

7. Which of the following is not an OOPS concept in Java?

8 / 15

8. What is the default value of String variable?

9 / 15

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

            }

       }

10 / 15

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

11 / 15

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

        class A 

        {

            int i;

            public void display() 

            {

                System.out.println(i);

            }    

        }    

        class B extends A 

       {

            int j;

            public void display() 

            {

                System.out.println(j);

            } 

        }    

        class Dynamic_dispatch 

       {

            public static void main(String args[])

            {

                B obj2 = new B();

                obj2.i = 1;

                obj2.j = 2;

                A r;

                r = obj2;

                r.display();     

            }

       }

12 / 15

12. How is Date stored in database?

13 / 15

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

        }

    }

14 / 15

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

            }

       }

15 / 15

15. 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 */ 
     }
   }

Your score is

The average score is 35%

0%

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