Java Quiz

0 votes, 0 avg
371

Java Questions

1 / 15

1. Find the output of the following code.

        import java.util.*;

        class Collection_iterators 

        {

            public static void main(String args[]) 

            {

                LinkedList list = new LinkedList();

                list.add(new Integer(2));

                list.add(new Integer(8));

                list.add(new Integer(5));

                list.add(new Integer(1));

                Iterator i = list.iterator();

                Collections.reverse(list);

    	    Collections.sort(list);

                while(i.hasNext())

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

            }

        }

2 / 15

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

3 / 15

3. How to convert Date object to String?

4 / 15

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

5 / 15

5.  The following program is an example for?

class Student{
int id;
String name;

void display(){System.out.println(id+" "+name);}

public static void main(String args[]){
Student s1=new Student();
Student s2=new Student();
s1.display();
s2.display();
}
} 

6 / 15

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

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 the following is a superclass of every class in Java?

9 / 15

9. Find the output of the following code.

import java.util.Scanner;

class ThisKeyword {
  private int a = 4;
  private int b = 1;

  void getSum(int a, int b) {
    this.a = a;
    this.b = b;
    System.out.println(this.a + this.b);
  }
}

public class Main {
  public static void main(String args[]) {
    ThisKeyword T = new ThisKeyword();
    T.getSum(3, 5);
  }
}

10 / 15

10. Which of the following is true in regard to applet execution?

11 / 15

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

12 / 15

12. What is the default value of String variable?

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

15 / 15

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

            } 

        }

Your score is

The average score is 36%

0%