Core Java 1

20 Questions | Attempts: 268
Share

SettingsSettingsSettings
Core Java 1 - Quiz

This questions are about the core java concepts includeing language fundamentals, objects,interfaces,threads,loops,collections and garbage collections. . .


Questions and Answers
  • 1. 

    Which three are valid declarations of a char?
    1. char c1 = 064770;
    2. char c2 = 'face';
    3. char c3 = 0xbeef;
    4. char c4 = \u0022;
    5. char c5 = '\iface';
    6. char c6 = '\uface';

    • A.

      1,2,4

    • B.

      1,3,6

    • C.

      3,5

    • D.

      5 only

    Correct Answer
    B. 1,3,6
  • 2. 

    Which four options describe the correct default values for array elements of the types indicated?
    1. int -> 0
    2. String -> "null"
    3. Dog -> null
    4. char -> '\u0000'
    5. float -> 0.0f
    6. boolean -> true

    • A.

      1,2,3,4

    • B.

      1,3,4,5

    • C.

      2,4,5,6

    • D.

      3,4,5,6

    Correct Answer
    B. 1,3,4,5
  • 3. 

    Public class Outer {     public void someOuterMethod()     {         //Line 5     }     public class Inner { }         public static void main(String[] argv)     {         Outer ot = new Outer();         //Line 10     } } Which of the following code fragments inserted, will allow to compile?

    • A.

      New Inner(); //At line 5

    • B.

      New Inner(); //At line 10

    • C.

      New ot.Inner(); //At line 10

    • D.

      New Outer.Inner(); //At line 10

    Correct Answer
    A. New Inner(); //At line 5
  • 4. 

    Which cause a compiler error? (choose all that apply)

    • A.

      Float[ ] f = new float(3);

    • B.

      Float f2[ ] = new float[ ];

    • C.

      Float[ ]f1 = new float[3];

    • D.

      Float f3[ ] = new float[3];

    Correct Answer(s)
    A. Float[ ] f = new float(3);
    B. Float f2[ ] = new float[ ];
  • 5. 

    Public class Runner {                 public static void main(String args[])                 {                     System.out.println(“This is a correct program”);                     continue;                 } } State True or False: The above program prints a output

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
  • 6. 

    What will be the output of the program? class Test {     public static void main(String [] args)     {         int x=20;         String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";         System.out.println(sup);     } }

    • A.

      Small

    • B.

      Tiny

    • C.

      Huge

    • D.

      Compilation fails

    Correct Answer
    B. Tiny
  • 7. 

    What will be the output of the program? class Bitwise {     public static void main(String [] args)     {         int x = 11 & 9;         int y = x ^ 3;         System.out.println( y | 12 );     } }

    • A.

      0

    • B.

      7

    • C.

      8

    • D.

      14

    Correct Answer
    D. 14
  • 8. 

    What will be the output of the program? public class X {     public static void main(String [] args)     {         try         {             badMethod();              System.out.print("A");         }          catch (Exception ex)         {             System.out.print("B");         }          finally         {             System.out.print("C");         }          System.out.print("D");     }      public static void badMethod() {} }

    • A.

      AC

    • B.

      BC

    • C.

      ACD

    • D.

      ABCD

    Correct Answer
    C. ACD
  • 9. 

    Public void test(int x) {     int odd = 1;     if(odd) /* Line 4 */     {         System.out.println("odd");     }     else     {         System.out.println("even");     } } Which statement is true?

    • A.

      Compilation fails

    • B.

      "odd" will always be output.

    • C.

      "even" will always be output.

    • D.

      "odd" will be output for odd values of x, and "even" for even values.

    Correct Answer
    A. Compilation fails
  • 10. 

    try {     int x = 0;     int y = 5 / x; } catch (Exception e) {     System.out.println("Exception"); } catch (ArithmeticException ae) {     System.out.println(" Arithmetic Exception"); } System.out.println("finished");   State True or False: The output of the above code is the below Exception finished

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
  • 11. 

    Suppose that you would like to create an instance of a new Map that has an iteration order that is the same as the iteration order of an existing instance of a Map. Which concrete implementation of the Map interface should be used for the new instance?

    • A.

      TreeMap

    • B.

      HashMap

    • C.

      LinkedHashMap

    • D.

      The answer depends on the implementation of the existing instance.

    Correct Answer
    C. LinkedHashMap
  • 12. 

    Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO (first-in, first-out) sequence?

    • A.

      Java.util.ArrayList

    • B.

      Java.util.LinkedHashMap

    • C.

      Java.util.HashMap

    • D.

      Java.util.TreeMap

    Correct Answer
    B. Java.util.LinkedHashMap
  • 13. 

    /* Missing Statement ? */ public class foo {     public static void main(String[]args)throws Exception     {         java.io.PrintWriter out = new java.io.PrintWriter();         new java.io.OutputStreamWriter(System.out,true);         out.println("Hello");     } } What line of code should replace the missing statement to make this program compile?

    • A.

      No statement required.

    • B.

      Import java.io.*;

    • C.

      Import java.io.PrintWriter;

    • D.

      #include java.io.*;

    Correct Answer
    A. No statement required.
  • 14. 

    Which of the following are Java reserved words?

    • A.

      Constant

    • B.

      Null

    • C.

      Default

    • D.

      Implement

    Correct Answer(s)
    B. Null
    C. Default
  • 15. 

    State the below statement is not false about static nested class:  It’s variables and methods must be static

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
  • 16. 

    Class X implements Runnable {     public static void main(String args[])     {         /* Missing code? */     }     public void run() {} } Which of the following line of code is suitable to start a thread ?

    • A.

      Thread t = new Thread(X);

    • B.

      Thread t = new Thread(X); t.start();

    • C.

      X run = new X(); Thread t = new Thread(run); t.start();

    • D.

      Thread t = new Thread(); x.run();

    Correct Answer
    C. X run = new X(); Thread t = new Thread(run); t.start();
  • 17. 

    Which three guarantee that a thread will leave the running state?
    1. yield()
    2. wait()
    3. notify()
    4. notifyAll()
    5. sleep(1000)
    6. aLiveThread.join()
    7. Thread.killThread()

    • A.

      1,2 and 4

    • B.

      2,5 and 6

    • C.

      3,4 and 7

    • D.

      4,5 and 7

    Correct Answer
    B. 2,5 and 6
  • 18. 

    Public class X {     public static void main(String [] args)     {         X x = new X();         X x2 = m1(x); /* Line 6 */         X x4 = new X();         x2 = x4; /* Line 8 */         doComplexStuff();     }     static X m1(X mx)     {         mx = new X();         return mx;     } } After line 8 runs. how many objects are eligible for garbage collection?

    • A.

      0

    • B.

      1

    • C.

      2

    • D.

      3

    Correct Answer
    B. 1
  • 19. 

    Which of the following would compile without error?

    • A.

      Int a = Math.abs(-5);

    • B.

      Int b = Math.abs(5.0);

    • C.

      Int c = Math.abs(5.5F);

    • D.

      Int d = Math.abs(5L);

    Correct Answer
    A. Int a = Math.abs(-5);
  • 20. 

    What is the output for the below code ? public class A {        public A() {         System.out.println("A"); } } public class B extends A implements Serializable {        public B() {         System.out.println("B");     } } public class Test {               public static void main(String... args) throws Exception {               B b = new B();                ObjectOutputStream save = new ObjectOutputStream(new FileOutputStream("datafile"));         save.writeObject(b);         save.flush();                  ObjectInputStream restore = new ObjectInputStream(new FileInputStream("datafile"));         B z = (B) restore.readObject();                }        }

    • A.

      A B A

    • B.

      A B A B

    • C.

      B B

    • D.

      A B

    Correct Answer
    A. A B A

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 15, 2016
    Quiz Edited by
    ProProfs Editorial Team
  • Dec 15, 2011
    Quiz Created by
    JQuizMaster
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.