Java Questions

0 votes, 0 avg
1

Java Questions

1 / 15

1. Which concept of Java is achieved by combining methods and attribute into a class?

2 / 15

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

            } 

        }

3 / 15

3. What is the syntax for java main method?

4 / 15

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

5 / 15

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

            }

        }

6 / 15

6. Which mechanism is used when a thread is paused running in its critical section and another thread is allowed to enter (or lock) in the same critical section to be executed?

7 / 15

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

}

}


                            

8 / 15

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

9 / 15

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

            } 

        }

10 / 15

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

11 / 15

11. How is Date stored in database?

12 / 15

12. What is the function of javap command?

13 / 15

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

14 / 15

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

15 / 15

15. Find the value of A[1] after execution of the following program.

int[] A = {0,2,4,1,3};
for(int i = 0; i < a.length; i++){
    a[i] = a[(a[i] + 3) % a.length];
}

Your score is

The average score is 27%

0%