Java Quiz

0 votes, 0 avg
367

Java Questions

1 / 15

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

2 / 15

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

        class test 

        {

            int a;

            int b;

            void meth(int i , int j) 

            {

                i *= 2;

                j /= 2;

            }          

        }    

        class Output 

        {

            public static void main(String args[])

            {

                test obj = new test();

    	    int a = 10;

                int b = 20;             

                obj.meth(a , b);

                System.out.println(a + " " + b);        

            } 

        }

3 / 15

3. Identify the output of the following program.

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

4 / 15

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

5 / 15

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

6 / 15

6. What is the default value of String variable?

7 / 15

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

            }

        }

8 / 15

8. Which of these keywords is used to prevent content of a variable from being modified?

9 / 15

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

10 / 15

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

11 / 15

11. Find the output of the following code.

Public class Solution{
         Public static void main(String args[]){
                 Int i;
                 for(i = 1; i < 6; i++){ 
                     if(i > 3) continue;
                 }
                 System.out.println(i);
          }
}

12 / 15

12. 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'));

            }

        }

13 / 15

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

14 / 15

14. How many objects will be created in the following?

String a = new String(“Interviewbit”);
String b = new String(“Interviewbit”);
Strinc c = “Interviewbit”;
String d = “Interviewbit”;

15 / 15

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

            }

       }

Your score is

The average score is 36%

0%