Java Aptitude

Java OCJP

OCJP Practice MCQ 2

  1. Guess the output:

    public class HelloWorld {
    
     public static void main(String argv[]) {
      int $7;
      
      System.out.println($7);
     }
    }
    
    
     

    A.

    B.

    C.

    D.

  2. Read the below code-snippet

    public class Test {
    
          int num;
          boolean isTrue;
          static int num1;
    
          public void printValue() {
    
                System.out.print(num);
                System.out.print(isTrue);
                System.out.print(num1);
          }
    }
    
    class HelloWorld{
    
          public static void main(String argv[]) {
                Test test= new Test();
                test.printValue();
          }
    }

    Guess the Output?

     

    A.

    B.

    C.

    D.

  3. A team of programmers is involved in reviewing a proposed design for a new utility class. After some discussion, they realize that the current design allows other classes to access methods in the utility class that should be accessible only to methods within the utility class itself. What design issue has the team discovered?

    A.

    B.

    C.

    D.

  4. public class Sample1 {
    	public static void main(String[] args) {
    		Integer n = 1; 
    		int i = 1; 
    		System.out.print(n.equals(i)); 
    		System.out.print(n == i); 
    	}
    }
    
    

    What is the output of the code?

    A.

    B.

    C.

    D.

  5. public class Sample1 {
    	public static void main(String[] args) {
    		Boolean b1 = new Boolean(true);
    		String s1 = new String("abcd");
    		String s2 = new String("abcd");
    		Boolean b4 = new Boolean(b1);
    
    		System.out.print(b1.equals(b4) + " ");
    		System.out.print((s1 == s2) + " ");
    		System.out.print(b1 == b4);
    	}
    }
    
    

    What is the output? 

    A.

    B.

    C.

    D.

  6. 1. public interface Status {

    2. /* insert code here */ int MY_VALUE = 10;

    3. }

     

    Which are valid insertion on line 2?

     

    A.

    B.

    C.

    D.

  7. public class Sample1 {
    
    	int i;
    
    	public static void main(String[] args) {
    		for(i=0;i<5;i++){
    			System.out.print(i);
    		}
    
    	}
    }
    

    What is the output of above code?

    A.

    B.

    C.

    D.

  8. public class Sample {
    	public static void main(String args[]) { 
    		int k=1, m=3;
    		do {
    			k=++k;
    			m--;
    		} while(m>0);
    		System.out.println(k);
    	}
    }
    
    

    What is the output?

    A.

    B.

    C.

    D.

  9. import java.util.*;
    
    public class SortCollect {
    
       public static void main(String[] args) {
          ArrayList<Integer> a = new ArrayList<Integer>();
          a.add(1); a.add(5); a.add(3);
          Collections.sort(a);
          a.add(2);
    
          Collections.reverse(a);
          System.out.println(a);
       }
    }
    

    What is the output?

    A.

    B.

    C.

    D.

  10. As a programmer you are creating an algorithm that requires a java.util.List that will provides an efficient implementation of add(0, object), but it does NOT need to support quick random access. What would be more suitable for your algorithm?

     

    A.

    B.

    C.

    D.


Please Share this page
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!