Accolite Java Hiring Challenge

                                  Accolite Java Hiring Challenge
 
Java MCQ's:
 
 
1.      What is the output of the following Java code:
import java.util.*;
class ABC
    {
        public int i = 0;
        public ABC(String text) /* Line 4 */
        {
            i = 1;
        }
    }
    class XYZ extends ABC
    {
        public XYZ(String text)
        {
            i = 2;
        }
        public static void main(String args[])
        {
            XYZ sub = new XYZ("Hi");
            System.out.println(sub.i);
        }
    }
Answer:  Compile time error
 
2.    What is the output of the following Java code:
import java.util.*;
public class ABC extends Thread{
    public static void main(String[] args) {
        Thread t1 = new Thread("T1");
        Thread t2 = new Thread("T2");
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            System.out.println("Main Thread interrupted.");
        }
    }
    public void run(){
        System.out.println("Run executed");
    }
}
Answer: No output
3.     What is the output of the following Java code:
import java.util.*;
        public class ABC
    {
        {
         final Vector s;
         s=new Vector();
        }
        public ABC()
     {
     }
        public void XYZ()
        {
        System.out.println(s.isEmpty());
        }
        public static void main(String args[])
       {
    new ABC().XYZ();
    }
    }
Answer: Compilation Error: Cannot find the symbol
4.      What is the output of the following Java code:
import java.util.*;
       public class ABC {
    static String v = "abc";
    static int v1 = 25;
    static {
        v1 = 50;
        System.out.println(v);
        System.out.println(v1);
    }
    public static void main(String args[]){
    }
}
Answer: abc 50
5.      What is the output of the following Java code:
import java.util.*;
public class ABC {
        public static void main(String [] args) {
            int i = 2, j = 3, k = 10;
            for (;i < 6;i++) {
                j = (++j + k++);
                System.out.println(j+k);
            }
        }
    }
Answer :   25 38 52 67
6.      In Java, which of the following interfaces is used to save unique elements in collections and to enable accessibility in the natural order?
Answer: java.util.Set
7.      What is the output of the following Java code:
class ABC{
        public static void main(String args[])
        {
            String X[] = {"m", "n", "p", "m", "p"};
            for (int i = 0; i < X.length; ++i)
                for (int j = i + 1; j < X.length; ++j)
                    if(X[i].compareTo(X[j]) == 0)
                System.out.print(X[j]);
            }
        }
Answer:  mp
8.      What is the output of the following Java code:
import java.util.*;
       class ABC {
    public static void main(String args[]) {
        String a1 = "Stop";
        StringBuffer ab = new StringBuffer(a1);
        ab.reverse();
        a1.concat(ab.toString());
        System.out.println(a1 + ab + a1.length() + ab.length());
    }
}                                                                                                                           
 
 Answer: StoppotS44
Note: Since the string is mutable
9.      What is the output of the following Java code:
import java.util.*;
class ABC {
    public static void main(String args[]) throws Exception {
        byte a = 4;
        byte b = 6;
        System.out.print((b%a) + ", ");
        System.out.println(b == ( (b/a)*a + (b%a) ));
    }
}                                                                                                                           

 

Answer: 2, true
 
10.What is the output of the following Java code:
import java.util.*;
public class XYZ{
    void addTwo(int varM) {
        varM += 3;
    }
    public static void main(String[] args){
        int varM = 0;
        addTwo(varM++);
        System.out.println(varM);
    }
}
                     Answer:  Compiler error

 

        error: non-static method addTwo(int) cannot be referenced from a static context

Please do comment If u have any Queries!

Add a Comment

Your email address will not be published. Required fields are marked *