Ads Sponsored By Google :)

Wednesday, 14 August 2013

Core Java Written Test Questions and Answers Explanation PDF Download

java written test questions and answers, java written test questions, java questions and answers for written test,core java written test questions and answers, java written test questions with answers,core java written test, Core Java Written Test Questions Pdf Download, Core Java Written Test Questions Pdf Download.

                               1          2         3        4         5       6 

Core Java Written Test Questions and Answers with Explanation 

This Article will Helps to the candidates who are going to attend for the Freshers and experience 2+,3+, etc..  Candidates. The main aim of this article to helps Candidates who are going for the Java Walkins, Interview. Before that if any Core Java written test, is going to conduct by the Company. Here it self candidates can find the all core java programmatic questions are available here.

  If you go through these Questions and Answers in through can find the much more questions on java.
You Can test programmatic and logical skills here.
Java Written Test Questions & Answers with Explanation

 1) What is the Ouput of this Program? 

      public static void main(String[] args) {
         Object demo = new Object() // inner Class    {
           public int hashCode() //override method from Object Class        {
           return 99;

Options :
    a)  99 b) Compile Error at Line 5 c) Compile Erroe at line 5 d) Runtime Error

Answer : A

Explanation :
  From the  above code is we can observe the anonymous inner class implementation. An Inner Class Can extends and implements the interface or Class. From the Question annoynous class extends the Object Class and overrides the methods hashCode() returns a value.  Result for the above question is 99. We cannot get any Compile time, run time errors.

2.  Null is a keyword in Java ?

   A. True B. False.

 Answer : Option A

3. Which is a valid keyword in java? 

A. interface B. string C. Float D. unsigned  

Answer: Option A


From the above Question( which is valid keyword) interface is a valid keyword. String Option B,C is Wrong because “String”, “Float”, is a Class type in Java. Keyword for Java primitive data types is “float”(Keyword). Even Option D is also wrong. 

4. From the below Options what are default values for array elements of types indicated ?

1.  int   -> 0       2. String  -> "null"      3. Dog  -> null             4. char  -> '\u0000'
5.  float  -> 0.0f           6. boolean  -> true

  1, 3, 4, 5    B. 1, 2, 3, 4     C. 1,2, 4, 5,     D. 3, 4, 5, 6  

Answer:  Option A


From the above case value of array data types default values for the 1,3,4,5 are correct. But Option no 2) is wrong because default values of String is null, without quotes. Option no 6) is wrong because the default value for boolean is false.

 5) Which of the following is valid declaration for array? 

1. char [] startsWith [];
2. int [] Score;
3. char [8] dist;
4. School students[];
5. School students[5];
1, 2, 4  B.  2,, 4, 5    C. 2, 3, 4 D. All are correct.

Answer:  Option A


From the above question Options in a list 1,2,4 are valid array declarations. In which brackets are allowed in the both sides of the variable. So options 1, 2, 4 are recommended. But Option number 3,5 are wrongs because size of array is declared when the array is initialized (JVM needs to know the space how much is allocate for array is on the basis of the size that is specified.

5.  Which of the following method or a class is not allowed directly to stop a thread ?
A. notify()         B. wait()  C.  InputStream access        D. sleep()

Answer: Option A


Option 1) notify() is used to wake up the thread that is waiting on the Object monitor. Option 2) is wrong, because this method wait() makes the current thread wait for another thread attempts to involve the notify(), Option 3)also wrong InputStream Class Methods blocks the input data,  when the end of the Stream is detected, or any exception is thrown. Here Blocking stands for stopping the thread for certain amount of time. Option d) is also wrong Sleep() is also allows the thread to sleep for some milli seconds of time. 

6. In this Below which of the following statement is suitable to start the thread?

  class ABC implements Runnable { 
    Public static void main(String args[])     {
   /**** Some Code is Missing Here *****/
    public void run() {} 
  A.     Thread t = new Thread(ABC);         B.  Thread t = new Thread(ABC); t.start();
  C.      ABC run = new ABC();  Thread t = new Thread(run); t.start(); 
  D. Thread t = new Thread();;

Answer: Option C


Option c is suitable to start the thread, because Runnable is an interface we cannot instantiate the Runnable Interface directly, by creating the object of sub class ABC, pass the object of ABC Class to thread class as an argument, then start the thread.
Option A), B), D) are wrong because Thread is not extended to ABC Class, then how we instantiate for the Thread Class.

7. What is the Ouput of this Program? 
  public void Valid(int i)  { 
       int i = 1; 
       int j=10;
      if(i) // Line No 5    {
    else    {

  A.Compilation fails.   B.  i C. y   D. Run time Error or Exception

Answer: Option A

From the above Program we can understand that at line number five we get the compile time error, because required type is Boolean, found is int.

9. What is the Excepted Out Put Of the Following program ?
public class BoolTest {
    public static void main(String [] args)     {
        int count = 0;
        Boolean a1 = new Boolean("TRUE");
        Boolean a2 = new Boolean("true");
        Boolean a3 = new Boolean("tRuE");
        Boolean a4 = new Boolean("false");
        if (a1 == a2)  // Line 8
            count = 1;
        if (a1.equals(a2) )// Line 10
            count = count+ 10;
        if (a2 == a4)  // Line 12
            count = count + 100;
        if (a2.equals(a4) )// Line 14
            count = count + 1000;
        if (a2.equals(a3) ) // Line 16
            count = count + 10000;
        System.out.println("count = " + count);
  A. 0 B. 1 C. 10 D. 10010

Answer: Option D

Explanation :
In the Above Question Line number 10 compilation fails because a1 and a2 are different references or objects. Line 10 and16 are succeed because of Boolean String constructors, Line No 12 and 16 fails because true is not equals to false.

10. What is the Excepted Output?

  class Hill 
    public static void main(String[] args)     {
        int a1 = 5; 
        int a2 = 6; 
        String k1 = "7"; 
        System.out.println(a1 + a2 + k1);  // Line No 6
A. 18 B. 117 C. 567 D. Compiler error

Answer: Option B

For More Written Test Questions and Answers

                               1          2         3        4         5       6

No comments:

Post a Comment