Can You Pass This Java Test? Quiz

20 Questions | Total Attempts: 126

SettingsSettingsSettings
Please wait...
Java Quizzes & Trivia

.


Questions and Answers
  • 1. 
    What is the output for the below code ? public class Test {                 public static void main(String[] args) {                                 List list = new ArrayList();                                 list.add(0, 59);                                 int total = list.get(0);                                 System.out.println(total);} }
    • A. 

      A)59

    • B. 

      B)Compile time error, because you have to do int total = ((Integer)(list.get(0))).intValue();

    • C. 

      C)Compile time error, because can't add primitive type in List.

    • D. 

      D)Compile Properly but Runtime Exception

  • 2. 
    Class A {             Try             {                         Class.forName(“jdbc:odbc:DriverManager”);             }             Catch(Exception e)             {             } }  
    • A. 

      1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver 1.jdbc:odbc:Driver Manager just Load the Driver 2.Load and initialize the Driver 3.load,initialize and register the driver jdbc:odbc:Driver Manager just Load the Driver

    • B. 

      Load and initialize the Driver

    • C. 

      Load,initialize and register the driver

  • 3. 
    Select the true statements in the following
    • A. 

      Runtime exceptions can be handled through catch with errors

    • B. 

      Runtime exceptions need not have throws declaration

    • C. 

      If throws is given, then try catch block should be used

    • D. 

      Runtime exceptions can be handled if it is extended by error class

  • 4. 
    Statement A:Anonymous class can extend class and implement interface at a time     Statement B:Anonymous class can have own members
    • A. 

      A is true,B is false

    • B. 

      A is false,B is true

    • C. 

      A is true,B is true

    • D. 

      A is false,B is false

  • 5. 
    Class A {             Try//line 1             {//line 2                         //Statement   //line 3 }//line 4 }    
    • A. 

      Shows uncaught exceptions at line 4

    • B. 

      Shows uncaught exceptions at line 5

    • C. 

      Demands finally block at line 4

    • D. 

      Demands finally block at line 5

  • 6. 
    1. Vector 2.HashSet 3.TreeSet 4.ArrayList i)Null Values ii)when getting values, sorted and stored iii)not ordered and sorted iv)Capacity            
    • A. 

      1-iii, 2-iv, 3-ii, 4-i

    • B. 

      1-i, 2-ii, 3-iii, 4-iv

    • C. 

      1-iv , 2-iii, 3-ii, 4-i

    • D. 

      1-iv, 2-iii, 3-i, 4-ii

  • 7. 
    1)final 2)abstract 3)private i)objects in subclass cant be access these ii)can’t override iii)cant instantiate
    • A. 

      1 - i , 2 - iii , 3 - ii

    • B. 

      1 - ii , 2 - i , 3 - iii

    • C. 

      1 - i, 2 - ii , 3 - iii

    • D. 

      1 – ii , 2 – iii , 3 – i

  • 8. 
    Class TestReturn{       Public static void main(string args[]) {              Int i=10;             SOP(“Result : ”+ getSquare(i));               }  Public static int getSquare (int i)                        {                Return i*i;              SOP(“END OF GET SQUARE”);                                 } }
    • A. 

      A)100

    • B. 

      B)runtime error

    • C. 

      C) END OF GET SQUARE , 100

    • D. 

      D) 100 , END OF GET SQUARE

    • E. 

      E) compile error

  • 9. 
    Set of services provided by component or class is called as
    • A. 

      A.interface

    • B. 

      B.container

    • C. 

      C.component

    • D. 

      D.object

  • 10. 
    A. Employee(){} b.Public Employee(){} c.Private Employee(){} i)no argument constructor ii)does not allow instantiation outside package iii)does not allow instantiation inside package
    • A. 

      1.a-i,b-ii,c-iii

    • B. 

      2.a-ii,b-iii,c-i

    • C. 

      3.a-iii,b-ii,c-i

    • D. 

      4)b-i , a- ii , c - iii

  • 11. 
    Which of the following best matches the example of television
    • A. 

      1.Encapsulation

    • B. 

      2.polymorphism

    • C. 

      3.Inheritance

  • 12. 
    Public class Eat { Eat(){System.out.println(“Eat”);} class chocolate{ chocolate(){System.out.println(“chocolate”);} public void eat() {System.out.println(“Fruit”);} }             public static void main(String a[])             {             Eat f=new Eat();              f.method(); } Public void method() {   new  chocolate(){}.eat(); } }
    • A. 

      1.eat chocolate fruit

    • B. 

      2.compilation error

    • C. 

      3.Runtime error

    • D. 

      4.eat fruit

  • 13. 
    Consider the following code: public class Code17 { public static void main(String args[]) { new Code17(); } { System.out.print("Planet "); }  { System.out.print("Welcome "); } } Which of the following will be the valid output for the above code?  
    • A. 

      A. Compilation Error

    • B. 

      B.Compiles and Executes with no output

    • C. 

      C. Planet

    • D. 

      D. Welcome Planet

    • E. 

      E. Planet Welcome

  • 14. 
    1. public class Foo { 2. public static void main(String[] args) { 3. try { 4. return; 5. } finally { 6. System.out.println( "Finally" ); 7. } 8. } 9. } What is the result?
    • A. 

      A. Finally

    • B. 

      B. Compilation fails.

    • C. 

      C. The code runs with no output

    • D. 

      D. An exception is thrown at runtime

  • 15. 
    1.enum Animals{ 2.DOG("woof"),CAT("meow"),FISH("burble"); 3.String sound; 4.Animals(String s) { sound=s;} 5.} 6.class TestEnum{ 7.static Animals a; 8.public static void main(String[] args){ 9.System.out.println(a.DOG.sound+" "+a.FISH.sound); 10.} 11.}
    • A. 

      A.woof burble.

    • B. 

      B.multiple compilation errors.

    • C. 

      C.Compilation fails due to an error on line 2.

    • D. 

      D.Compilation fails due to an error on line 3

    • E. 

      E.Compilation fails due to an error on line 4.

    • F. 

      F.Compilation fails due to an error on line 9

  • 16. 
    Which declare a compilable abstract class?
    • A. 

      A.public abstract class Canine{public Bark speak();}

    • B. 

      B.public abstract class Canine{public Bark speak(){}}

    • C. 

      C.public class Canine{public abstract Bark speak();}

    • D. 

      D.public class canine abstract{public abstract Bark speak();}

  • 17. 
    1.enumA{A} 2.class E2{ 3.enum B{B} 4.void C(){ 5.enum D{ D} 6.} 7.}
    • A. 

      A.The code compiles

    • B. 

      B.If only line 1 is removed the code compiles

    • C. 

      C.If only line3 is removed the code compiles

    • D. 

      D.If only line 5 is removed the code compiles.

    • E. 

      E.If lines 1 and 3 are removed the code compiles.

    • F. 

      F.If lines 1,3 and 5 are removed the code compiles

  • 18. 
    protected Hmpf h; } class Woop extends Zing{ } class Hmpf{ } Which is true?
    • A. 

      A.Woop is-a Hmpf and has-a Zing

    • B. 

      B.Zing is-a Woop and has-a Hmpf

    • C. 

      C.Hmpf has-a Woop and Woop is-a Zing.

    • D. 

      D.Woop has-a Hmpf and Woop is-a Zing

    • E. 

      E.Zing has-a Hmpf and Zing is-a Woop.

  • 19. 
    Class Uber{ static int y=2; Uber(int x) { this(); y=y*2; } Uber() { y++; } class Minor extends Uber{ Minor() { super(y); y=y+3; } public static void main(String[] args) { new Minor(); System.out.println(y); } } What is the result?
    • A. 

      6

    • B. 

      7

    • C. 

      8

    • D. 

      9

    • E. 

      Compilation fails

    • F. 

      An exception is thrown.

  • 20. 
    Which statement is true?
    • A. 

      Has-a relationship always rely on inheritance.

    • B. 

      Has-a relationship always rely on instance variables.

    • C. 

      Has-a relationship always require atleast two class types.

    • D. 

      Has-a relationship always rely on polymorphism.

    • E. 

      Has-a relationships are always tightly coupled.