Java Quiz For Job Interview Questions

25 Questions | Total Attempts: 3635

SettingsSettingsSettings
Please wait...
Job Interview Quizzes & Trivia

Java Quiz for Job Interview


Questions and Answers
  • 1. 
    Public class Swap { public static void swapStrings(String x, String y){ String temp = x; x=y; y=temp; } public static void main(String[] args) { String a = "1"; String b = "2"; swapStrings(a, b); System.out.println("a="+a+" ,b="+b); }} What will be the output when executing this main?
    • A. 

      An exception will be thrown

    • B. 

      “a=2 ,b=1”

    • C. 

      “a=1 ,b=2” because strings are immutable

    • D. 

      “a=1 ,b=2” because Java passes parameters by value

  • 2. 
    Class Parent{ protected void x(){} public void y(){}}public class Child extends Parent{ public void x(){} protected void y(){}}
    • A. 

      It compiles successfully

    • B. 

      Compilation error – x can’t have its visibility increased

    • C. 

      Compilation error – y can not have its visibility reduced

    • D. 

      Compilation error – neither x nor y can have their visibility changed

  • 3. 
    Following code will result in: int a = 3.5;
    • A. 

      Compilation error

    • B. 

      Runtime error

    • C. 

      A being 3.5

    • D. 

      A being 3

  • 4. 
    Following code will result in: int a1 = 5; double a2 = (float) a1;
    • A. 

      Compilation error

    • B. 

      Runtime error

    • C. 

      No errors

  • 5. 
    Following code will result in: class A {    int b = 1;    public static void main(String[] args) {        System.out.println("b is " + b);    }}
    • A. 

      Compilation error

    • B. 

      Runtime Error

    • C. 

      Runtime Exception

    • D. 

      B is 1

  • 6. 
    Following code will result in: class A {    public static void main(String[] args) {        B b = new A();    }}class B extends A {}
    • A. 

      Compile error

    • B. 

      Runtime Exception

    • C. 

      No error

  • 7. 
    Following code will result in: class A {    public static void main(String[] args) {        A a = new B();    }}class B extends A {}
    • A. 

      Compiler error

    • B. 

      Runtime Exception

    • C. 

      No errors

  • 8. 
    Methods that are marked protected can be called in any subclass of that class
    • A. 

      True

    • B. 

      False

  • 9. 
    An abstract class can have non-abstract methods.
    • A. 

      True

    • B. 

      False

  • 10. 
    What is an instanceof
    • A. 

      A method in object

    • B. 

      An operator and keyword

  • 11. 
    Can you compare a boolean to an integer?
    • A. 

      True

    • B. 

      False

  • 12. 
    If class A implements an interface does it need to implement all methods of that interface?
    • A. 

      Yes, always

    • B. 

      No, not when A is abstract

  • 13. 
    Integer a = new Integer(2); Integer b = new Integer(2); What happens when you do if (a==b)?
    • A. 

      Compiler error

    • B. 

      Runtime Exception

    • C. 

      True

    • D. 

      False

  • 14. 
    Synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution.
    • A. 

      True

    • B. 

      False

  • 15. 
    Which ones does not extend java.lang.Number(you can make multiple choices)
    • A. 

      Integer

    • B. 

      Boolean

    • C. 

      Character

    • D. 

      Long

    • E. 

      Short

  • 16. 
    Which JDBC method is used to execute any SQL statement with a "SELECT" clause, that return the result of the query as a result set.
    • A. 

      ExecuteUpdate()

    • B. 

      ExecuteQuery()

    • C. 

      Execute()

  • 17. 
    Which JDBC method is used to execute INSERT, DELETE, UPDATE , and other SQL DDL such as CREATE, DROP TABLE.
    • A. 

      ExecuteUpdate()

    • B. 

      ExecuteQuery()

    • C. 

      Execute()

  • 18. 
    Which JDBC method is used for retrieving a string value (SQL type VARCHAR) and assigning into java String object.
    • A. 

      GetVarchar()

    • B. 

      GetObject()

    • C. 

      GetString()

  • 19. 
    This method is used for retrieving the value from current row as object.
    • A. 

      GetRow()

    • B. 

      GetObject()

    • C. 

      GetString()

  • 20. 
    The Connection.prepareStatement() method accepts a SQL query and returns a...
    • A. 

      PreparedStatement object

    • B. 

      CallableStatement object

    • C. 

      PrepareCall method

  • 21. 
    This method returns an integer value indicating a row count.
    • A. 

      ExecuteQuery()

    • B. 

      ExecuteUpdate()

    • C. 

      Execute()

  • 22. 
    Consider the following classpublic class Test implements Runnable{    public void run() {    }}Creating an instance of this class and calling its run() method will spawn a new thread.
    • A. 

      True

    • B. 

      False

  • 23. 
    What is the result of attempting to compile and run the following code?public class Test {    public static void main(String[] args){        Integer a = new Integer(4);        Integer b = new Integer(8);        Set hs = new HashSet();        hs.add(a);        hs.add(b);        hs.add(a);        System.out.println(hs.size());    }}
    • A. 

      It prints: 2

    • B. 

      It prints: 3

  • 24. 
    What is the result of attempting to compile and run the following code?public class Test {    public static void main(String[] args){        Integer a = new Integer(4);        Integer b = new Integer(8);        Integer c = new Integer(4);        Set hs = new HashSet();        hs.add(a);        hs.add(b);        hs.add(c);        System.out.println(hs.size());    }}
    • A. 

      It prints: 2

    • B. 

      It prints: 3

  • 25. 
    Class Figure {    public void print() {        System.out.println("FIGURE");    }}class Triangle extends Figure {    public void print() {        System.out.println("TRIANGLE");    }}public class Test {    public static void main(String[] args) {        Figure f1 = new Figure();        f1.print();        Figure f2 = new Triangle();        f2.print();        Triangle t = new Triangle();        t.print();    }}What will this program print out?
    • A. 

      FIGURE FIGURE FIGURE

    • B. 

      FIGURE FIGURE TRIANGLE

    • C. 

      FIGURE TRIANGLE TRIANGLE

Back to Top Back to top