Logo

Java Questions Set 74:

Quiz Mode

 

 How many ways to create an object 


1
2
3
4

Solution:

Predict the output of the following Java code.

1
2
3
4

Solution:

public class abekus {

public static void main(String[] args){

 String s = "abekus";

 int x = 0;

 

do {

 System.out.print(s.charAt(x));

 x++ ;

 } while (x < 2);

}

}

Solution:

Which of the following Java statements will not raise an error?

1
2
3
4

Solution:

How many times 'abekus' is printed?

public class abekus

{

public static void main(String[] args) {

while(true){

  System.out.println("abekus");

}

}

}

1
2
3
4

Solution:

class jj

{

public static void main(String args[])

StringBuffer sb = new StringBuffer("Abekus");

sb.replace(1,2,"Hello");

System.out.println(sb);

   }

}

1
2
3
4

Solution:

Statement 1- Interface allows us to call generic methods as a normal method 

Statement 2-Type Interface allows us to call generic methods as a normal method 

Statement 3- Inner class allows us to call generic methods as a normal method 

1
2
3
4

Solution:

Predict the output of the following Java code:

import java.util.Scanner;

public class Main

{

    public static void main(String args[])

    {

        StringBuffer s1 = new StringBuffer("Abekus");

        s1.insert(3 , "Abekus");

        System.out.println(s1);

    }

}

1
2
3
4

Solution:

Predict the output of the following Java code:

public class Abekus {

static Abekus A;

static int c = 0;

public static void main(String[] args) throws InterruptedException

{

Abekus A1 = new Abekus();

A1 = null;

System.gc();

Thread.sleep(500);

A = null;

System.gc();

Thread.sleep(500);

System.out.println("finalize() calls : " + c);

}

protected void finalize() {

c++;

A = this;

}

}

1
2
3
4

Solution:

import java.util.*;

    class output 

    {

        public static void main(String args[]) 

        {

            LinkedList set = new LinkedList();

            set.add(new Integer(3));

            set.add(new Integer(8));

            set.add(new Integer(5));

            set.add(new Integer(1));

   set.addFirst(new Integer(2));

   set.addLast(new Integer(2));

            Iterator i = set.iterator();

            Collections.reverse(set);

   Collections.shuffle(set);

            i.next();

            i.remove();

            while(i.hasNext())

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

        }

    }

1
2
3
4
5

Solution: