Java quiz questions

Java interview questions

  • 1.

    Which Protocol is used to deliver email to recipient mail Server?

    Options
    - SMTP
    - POP
    - IMAP
    - MAPI

    1. SMTP

    2. POP

    3. IMAP

    4. MAPI

    Answer
  • 2.

    What type of messaging in provided by JMS?

     

    1. Synchronous

    2. Asynchronous

    3. Both Synchronous ans Asynchronous

    4. None

    Answer
  • 3.

    Following program have compilation error, can you guess root cause of it?

    abstract class VQCourse {
        public String courseName;
        public String courseID;
    } public class VirtuQCourseProvide extends VQCourse {
        public static void main(String[]args) {
            VQCourse course1 = new VQCourse();
             course1.courseID = "0001";
             course1.courseName = "JAVA";
             System.out.println(course1.toString());
    }}
    1. Protected means only inherited class and class have access to protected members. 

    2. abstract class VQCourse should have a implemented method. 

    3. You cannot instantiate a abstract class

    4. Declare class VQCourse as final.

    Answer
  • 4.

    Code below has class VQClassB which inherits another class VQClassA, study following code carefully and choose correct option about program output.

    package com.vq.classes;
    public class VQClassB {
        class VQClassA {
            public VQClassA(int x) {
                this.x = x;
            } protected int x;
        } public VQClassB(int x, int x2, int y) {
            x = x2;
            this.y = y;
        }
        private VQClassB(int x, int y) {
            this.x = x;
            this.y = y;
        }
        private int x;
        private int y;
        public static void main(String[]args) {
            VQClassB vqb = new VQClassB(20, 10);
            VQClassB.VQClassA vqa = new VQClassB(10, 10).new VQClassA(10);
            System.out.println(vqa.x + " " + vqb.x);
        }
    }
    1. 10 10

    2. 10 20

    3. 20 20

    4. 20 10

    Answer
  • 5.

    ode below has class VQClassB which inherits another class VQClassA, study following code carefully and choose correct option about output of program.

    package com.vq.classes;
    class VQClassA {
        public VQClassA(int x) {
            this.x = x;
        } protected int x;
    }
    public class VQClassB extends VQClassA {
        public VQClassB(int x, int x2, int y) {
            super(x);
            x = x2;
            this.y = y;
        } private VQClassB(int x, int y) {
            super(x);
            this.x = x;
            this.y = y;
        }
        private int x;
        private int y;
        public static void main(String[]args) {
            VQClassA vqa = new VQClassA(10);
            VQClassB vqb = new VQClassB(20, 10);
            vqa = vqb;
            System.out.println(vqa.x + " " + vqb.y);
        }
    }
    1. 10 10

    2. 10 20

    3. 20 20

    4. 20 10

    5. None

    Answer
  • 6.

    Class VQCourse contains declaration about a course, which is inside package com.vq . You are declaring a new class VirtuQCourseProvider where you want to create a object of VQCourse but following program fails to compile. Choose option which eliminates compilation error.

    public class VirtuQCourseProvide {
        public static void main(String[]args) {
            VQCourse course1 = new VQCourse();
    }}
    1. Write a new class VQCourse.java 

    2. include a import statement vq.com.VQCourse.

    3. include a import statement package VQCourse 

    4. include a import statement VQCourse 

    5. None

    Answer
  • 7.

    Which of following statement(s) can result in new object instance creation if executed successfully.

    1. String str = new String(); 

    2. String str = new String("VirtuQ"); 

    3. String str = "VirtuQ" + " "+ Simplifying Education"; 

    4. int [] arr = {1,2,3,4,5}; 

    5. All

    Answer
  • 8.

    Choose correct equivalent statement of following code.

    int[][] arr = new int[3][];
    for (int i = 0; i < arr.length; i++)
        arr[i] = new int[3];
    1. int [][] arr = new int[3][];

    2. int [3][] arr = new int[3][]; 

    3. int [][3] arr = new int[3][]; 

    4. int [][] arr = new int[3][3];

    5. None

    Answer
  • 9.

    Which statement(s) is true about following program?

    public class VirtuQCourseProvide {
        public static void main(String[]args) {
            String firstName = "VirtuQ";
            String lastName = "Simplifying Education";
            String FullName = firstName + lastName;
            String courseProvider = FullName;
    }}
    1. The statement courseProvider==FullName will evaluate to true. 

    2. The statement courseProvider.equals(FullName) will evaluate to true. 

    3. The statement courseProvider.equals(courseProvider==firstName+lastName) will evaluate to true. 

    4. The statement courseProvider.equals(courseProvider==firstName+lastName) will evaluate to false 

    5. Options 1,2 & 4.

    Answer
  • 10.

    What will be the output of the program?

    String s = "hello"; 
    Object o = s; 
    if( o.equals(s) )
    {
        System.out.println("A"); 
    } 
    else
    {
        System.out.println("B"); 
    } 
    if( s.equals(o) )
    {
        System.out.println("C"); 
    } 
    else
    { 
        System.out.println("D"); 
    }
    1. A
    2. B
    3. C
    4. D
    1. 1 and 3

    2. 2 and 4

    3. 3 and 4

    4. 1 and 2

    Answer
  • 11.

    What will be the output of the program?

    public class ExamQuestion6 
    {
        static int x; 
        boolean catch()
        {
            x++; 
            return true; 
        } 
        public static void main(String[] args)
        {
            x=0; 
            if ((catch() | catch()) || catch()) 
                x++; 
            System.out.println(x); 
        } 
    }
    1. 1

    2. 2

    3. 3

    4. Compilation Fails

    Answer
  • 12.

    What will be the output of the program?

    try 
    {
        Float f1 = new Float("3.0");
        int x = f1.intValue();
        byte b = f1.byteValue();
        double d = f1.doubleValue();
        System.out.println(x + b + d);
    }
    catch (NumberFormatException e) /* Line 9 */
    {
        System.out.println("bad number"); /* Line 11 */
    }
    1. 9.0

    2. bad number

    3. Compilation fails on line 9.

    4. Compilation fails on line 11.

    Answer
  • 13.

    Which of the following statements is true?

    1. If assertions are compiled into a source file, and if no flags are included at runtime, assertions will execute by default.
    2. As of Java version 1.4, assertion statements are compiled by default.
    3. With the proper use of runtime arguments, it is possible to instruct the VM to disable assertions for a certain class, and to enable assertions for a certain package, at the same time.
    4. When evaluating command-line arguments, the VM gives -ea flags precedence over -da flags.
    1. 1

    2. 2

    3. 3

    4. 4

    Answer
  • 14.

    Which two statements are true?

    1. Deadlock will not occur if wait()/notify() is used
    2. A thread will resume execution as soon as its sleep duration expires.
    3. Synchronization can prevent two objects from being accessed by the same thread.
    4. The wait() method is overloaded to accept a duration.
    5. The notify() method is overloaded to accept a duration.
    6. Both wait() and notify() must be called from a synchronized context.
    1. 1 and 2

    2. 3 and 5

    3. 4 and 6

    4. 1 and 3

    Answer
  • 15.

    Which method must be defined by a class implementing the java.lang.Runnable interface?

    1. void run()

    2. public void run()

    3. public void start()

    4. void run(int priority)

    Answer
  • 16.

    Which of the following are true statements?

    1. The Iterator interface declares only three methods: hasNextnext and remove.
    2. The ListIterator interface extends both the List and Iterator interfaces.
    3. The ListIterator interface provides forward and backward iteration capabilities.
    4. The ListIterator interface provides the ability to modify the List during iteration.
    5. The ListIterator interface provides the ability to determine its position in the List.
    1. 2, 3, 4 and 5

    2. 1, 3, 4 and 5

    3. 3, 4 and 5

    4. 1, 2 and 3

    Answer
  • 17.

    What is the numerical range of char?

    1. 0 to 32767

    2. 0 to 65535

    3. -256 to 255

    4. -32768 to 32767

    Answer
  • 18.

    Which collection class allows you to access its elements by associating a key with an element's value, and provides synchronization?

    1. java.util.SortedMap

    2. java.util.TreeMap

    3. java.util.TreeSet

    4. java.util.Hashtable

    Answer
  • 19.

    You need to store elements in a collection that guarantees that no duplicates are stored. Which one of the following interfaces provide that capability?

    1. Java.util.Map

    2. Java.util.List

    3. Java.util.Collection

    4. None of the above

    Answer
  • 20.

    At Point X on line 5, which code is necessary to make the code compile?

    public class ExceptionTest 
    { 
        class TestException extends Exception {} 
        public void runTest() throws TestException {} 
        public void test() /* Point X */ 
        { 
            runTest(); 
        } 
    }
    1. No code is necessary.

    2. throws Exception

    3. catch ( Exception e )

    4. throws RuntimeException

    Answer

© 2017 QuizBucket.org