Logo

Java Questions Set 158:

Quiz Mode

Predict the output of the following Java code.

1
2
3
4

Solution:

What is the return type of a constructor?

1
2
3
4

Solution:

Which method is used to prevent thread execution?

1
2
3
4

Solution:

Which method of the FileReader class is used to read characters from a file?

1
2
3
4

Solution:

How do you configure JUnit tests to use PowerMock?

1
2
3
4

Solution:

 The process of defining the methods in a class having same name & different type signature is called

1
2
3
4

Solution:

What will be the output of the following Java code?


public class ex {

public static void main(String[] args) {

int x = 10, y = 20;

if (x > 15 || y > 10)

System.out.println(x);

else

System.out.println(y);

}

}


1
2
3
4

Solution:

// Predict the output

public class Main{

 public static void main(String args[])

 {

 int array[][] = { { 42, 2, 23},

 { 5, 60, 12},

 { 19, 10, 1},

 };

 function(array);

 }

 public static void function(int array[][])

 {

 for (int i = 0; i < 3; i++)

 {

 for (int j = 0; j < 3; j++)

 {

 System.out.print(array[j][i] + " ");

 }

 System.out.println();

 }

 }

}

1
2
3
4

Solution:

    import java.util.*;

    class output 

    {

        public static void main(String args[]) 

        {

            LinkedList obj = new LinkedList();

            obj.add("A");

            obj.add("B");

            obj.add("C");

obj.addLast(new Integer(25));

            obj.removeFirst();

            obj.removeLast();

obj.pollFirst();

obj.pollLast();

            System.out.println(obj);

        }

    }

1
2
3
4
5

Solution:

What will be the output of the following code?

class A

    {

        public int a;

  private int b;

        void cal(int x, int y)

        {

            a =  x + 1;

            b =  y;

        }        

    }    

    public class main

    {

        public static void main(String args[])

        {

            A a = new A();   

            obj.cal(1, 2);

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

        }

   }

1
2
3
4

Solution: