Logo

Java Questions Set 18:

Quiz Mode

Anonymous classes are mostly used for event handling.

1
2

Solution:

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

1
2
3
4

Solution:

public class operators {

public static void main(String[] args)

{

int a = 20, b = 10, c = 0, d = 20, e = 40, f = 30;

System.out.println((a%b * d - f));

}

}

Solution:

Which access specifier can be used for a class so that its members can be accessed by a different class in the same package?

1
2
3
4

Solution:

Which of the following is the correct definition of an immutable class in Java?

1
2
3
4

Solution:

What is the correct outptut?

 public class Abekus {

 int x = 5;

 public static void main(String[] args) {

  Abekus a = new Abekus();

  System.out.println(a.x+x);

 }

}

1
2
3
4

Solution:

The following code is an example of?

public classFirstClass {

    public static voidmain(String[] args)

    { 

    FirstClass f=new FirstClass();

    System.out.println(“My First class”);

   }

}

1
2
3
4

Solution:

Which of the following is the correct way to implement a singleton class in Java?

1
2
3
4
5

Solution:

Predict the output of the following Java code.

import java.util.*;

class Abekus {

public static void main(String args[]) {

Formatter F = new Formatter();

F.format("% d", 345);

System.out.println(F);

F.format("% d", -230);

System.out.println(F);

}

}

1
2
3
4

Solution:

import java.util.*;

    public class outputs 

    {

        public static void main(String args[]) 

        {

            LinkedList list = new LinkedList();

            list.add(new Integer(3));

            list.add(new Integer(9));

            list.add(new Integer(5));

            list.add(new Integer(1));

list.addFirst(new Integer(6));

list.addLast(new Integer(9));

            Iterator i = list.iterator();

       Collections.sort(list);

       System.out.print(list.peekFirst() + " "+ list.peekLast());

        }

    }

1
2
3
4

Solution: