Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SCJP Java Interview Questions Part-II

Today, I am sharing Java SCJP/OCJP Written Test Interview Questions with answers,earlier i have shared SCJP/OCJP Interview Questions part-I. In this page we will discuss more SCJP interview Questions more. Those are preparing to appear SCJP/OCJP Written Test,they should brush up these questions and my earlier post as well. 

1) int[] myArray=new int[]{1,2,3,4,5}; What allows you to create a list from this array?


A. List myList=myArray.asList();
B. List myList=Arrays.asList(myArray);
C. List myList=new ArrayList(myArray);
D. List myList=Collections.fromArray(myArray);

Answer: B

 class A
class B extends A{}
class C extends B{}
class D extends B{}
which three statements are true?(choose three)

A. The type Listis assignable to List
B. The type Listis assignable to List
C. The type Listis assignable to List>
D. The type List is assignable to List
E. The type Listis assignable to List
F. The type Listis assignable to any List reference
G. The type Listis assignable to List

Answer: CDG


public static void search(ListString> list)

What is the result of calling search with a valid List implementation ?

A. 0
B. 1
C. 2
D. a
E. b
F. c
G. The result is undefined

Answer: G


public class person
private name;
public Person(String name)
public int hashCode()
return 420;
Which statement is true?

A. The time to find the value form HashMap with a Person Key depends on the size of the map.

B. Deleting a Person Key form a HashMap will delete all map entries for all keys of type person.

C. Inserting a second Person Object into a HashSet will cause the first Person object to be removed as a duplicate.

D. The time to determine whether a Person object is contained in a HashSet is constant and does NOT depend on the size of the map.

Answer: A


23. HashMap props=new HashMap();
24. props.put("key45","some value");
25. porps.put("key12","some other value");
25. props.put("key39","yet another value");
26. Set s=props.keySet();
27.//insert code here

What,inserted at line 27,will sort the keys in the props HashMap?

A. Arrays.sort(s);
B. s=new TreeSet(s);
C. Collections.sort(s);
D. s=new Sortedset(s);

Answer: B


11.Object[] myObject={new Integer(12),new String("abc"),new Integer(15),new 12.Boolean(true)};
14.for(int i=0;i
16.System.out.println(" ");
What is the result?

A. Compailation fails due to an error in line 11
B. Compilation fails due to an error at line 13
C. A ClassCastException occurs in line 13
D. A ClassCastException occurs in line 15
E. The value of all four objects prints in natural order

Answer: C


import java.util.*;
public class Old{
public static Object get0(List list){
return list.get(0);
Which three will compile successfully?(choose three)

A. Object o=Old.get0(new LinkedList());
B. Object o=Old.get0(new LinkedList>());
C. Object o=Old.get0(new LinkedList());
D. Object o=Old.get0(new LinkedList());
E. String s=(String)Old.get0(new LinkedList());

Answer: A,D,E

Which two statements are true about the hashCode method?(Choose two)?

A. The hashCode method for a given class can be used to test for object equality and object inequality for that class

B. The hashCode method is used by the java.util.SortedSet collection class to order the elements within that set.

C. The hashCode method for a given class can be used to test for object inequality,but Not object equality,for that class.

D. The hashCode method is used by the java.util.HashSet collection class to group the elements within that set into hash buckets for swift retrieval.

Answer: C,D


A programmer has an algorithm that requires a java.util.List that provides an efficient implementation of add(0,object),but does NOT need to support quick random access.

What supports these requirements?

A. java.util.Queue
B. java.util.ArrayList
C. java.util.LinearList
D. java.util.LinkedList

Answer: D


public static void before(){
Set set=new TreeSet();
Iterator itr=set.iterator();
System.out.println(" ");

Which of the following statements are true?

A. the before() method will print 1 2
B. the before() method will print 1 2 3
C. the before() method will print three numbers,but the order cannot be determined
D. the before() method will not compile
E. the before() method will throw an exception at runtime.

Answer: E

Explanation: E is correct,you can not put both String and int into the same TreeSet. Without generics,the compiler has no way of knowing what type is appropriate for this TreeSet,so it allows everything to compile. At runtime, the TreeSet will try to sort the elements as they are added,and when it tries to compare an Integer with a String it will throw a ClassCastException. Note that although the before() method does not use generics,it does use autoboxing.

This post first appeared on Learnprogramingbyluckysir, please read the originial post: here

Share the post

SCJP Java Interview Questions Part-II


Subscribe to Learnprogramingbyluckysir

Get updates delivered right to your inbox!

Thank you for your subscription