Java Pool Bit Meerut

30 Questions | Attempts: 110
Share

SettingsSettingsSettings
Java Quizzes & Trivia

Testing java by online exam


Questions and Answers
  • 1. 
    What is java ?
    • A. 

      Oop language

    • B. 

      Structure language

    • C. 

      Procedural language

    • D. 

      Application language

    • E. 

      Software devlopment language

  • 2. 
    Which of these is a keyword in java?
    • A. 

      Goto

    • B. 

      Enum

    • C. 

      Switch

    • D. 

      Class

    • E. 

      Critical

  • 3. 
    Which is legal identifier name?
    • A. 

      Int __;

    • B. 

      Int $_1;

    • C. 

      Int 123;

    • D. 

      Int a*g;

    • E. 

      Int th_is;

  • 4. 
    "Tiger" is used to denote which version of java?
    • A. 

      Java 5.0

    • B. 

      Java 6.0

    • C. 

      Java 1.1

    • D. 

      Java 1.0

    • E. 

      Java 2.0

  • 5. 
    Which one of these is primitive datatype in java?
    • A. 

      Int

    • B. 

      Boolean

    • C. 

      Short

    • D. 

      Long

    • E. 

      Float

  • 6. 
    Try{int x=Integer.parseInt("two");}what type of exceptions can be caugth in catch block?
    • A. 

      IllegalStateException

    • B. 

      IllegalArgumentException

    • C. 

      NumberFormatException

    • D. 

      IllegalMonitorStateException

    • E. 

      ArrayIndexOutOfBoundException

  • 7. 
    Class A{static void sing(){System.out.print("fa");}}class B extends A{static void sing(){System.out.print("la";)}public static void main(String[] args){A one=new B();B two=new B();System.out.print(one.sing()+""+two.sing());}}}what is the result?
    • A. 

      Fa la

    • B. 

      La fa

    • C. 

      Fa fa

    • D. 

      La la

    • E. 

      Compilation fails

  • 8. 
    Class Top{Top(String s){System.out.println("Hello");}}class Bottom extends Top{Bottom(String t){}public static void main(String[] args){new Bottom("BIT"); }}what is the result?
    • A. 

      Hello

    • B. 

      No output is generated

    • C. 

      An Exception is thrown at run time

    • D. 

      Compilation fail

    • E. 

      None of above

  • 9. 
    Class Alpha{int over=1;}class Beta extends Alpha{int over=2; }class Gamma extends Beta{int over=3;public static void main(String[] args){new Gamma().go();}void go(){Beta b=new Gamma();Alpha a=new Gamma();System.out.println(super.over+""+b.over+""+a.over);}}what is the result?
    • A. 

      221

    • B. 

      321

    • C. 

      233

    • D. 

      333

    • E. 

      Compilation fails

  • 10. 
    Public class Switch2{public static short x=1;staticfinal int y=3;public static void main(String[] args){for(int z=3;z>0;--z){switch(z){case y:System.out.print("0");case y-1:System.out.print("1");case x:z--;}}}}what is the result?
    • A. 

      01

    • B. 

      012

    • C. 

      Compilation fails at line 7

    • D. 

      Compilation fails at line 8

    • E. 

      Compilation fails at line 9

  • 11. 
    Class Zeta{public static void main(String[] args){int x=1;if((4>x)^((++x + 2)>3)) x++;if((4 > ++x)^(++x==5)) x++;System.out.print(x);}}what is the result?
    • A. 

      2

    • B. 

      3

    • C. 

      4

    • D. 

      5

    • E. 

      Compilation fails

  • 12. 
    Which are true?
    • A. 

      A static method cannot be synchronized.

    • B. 

      If a class has synchronized code,multiple threads can still access the non-synchronized code.

    • C. 

      Variables can be marked synchronized

    • D. 

      When a thread sleeps,it releases its locks

    • E. 

      When a thread invockes wait(),it releases its locks

  • 13. 
    Public class MyProgram{public static void main(String[] args){try{  System.out.print("Hello World");}finally{System.out.println("Finally executing");}}}what is the result?
    • A. 

      Compilation fails

    • B. 

      Exception

    • C. 

      Hello world

    • D. 

      Hello world Finally executing

    • E. 

      Finally executing Hello world

  • 14. 
    Class Alpha{int doStuff(float b){return 7;}}class Beta extends Alha{//insert code here}which,inserted independently at line 8,will compile?
    • A. 

      Private int doStuff(float y){return 4;}

    • B. 

      Protected int doStuff(float y){return 4;}

    • C. 

      Public Integer doStuff(float y){return 4;}

    • D. 

      Final int doStuff(float y){return 4;}

    • E. 

      Public long doStuff(float y){return 4;}

  • 15. 
    Class Silky extends Smooth{int x=5;int y=7;public static void main(String[] args){new Silky().go();}void go(){if(x>y & (Boolean)(this instanceof Silky))  System.out.print("a");if(Long.valueOf(4) instanceof Number) System.out.print("b");}}class Smooth{}what is the result?
    • A. 

      A

    • B. 

      B

    • C. 

      Ab

    • D. 

      Compilation fails

    • E. 

      An exception is thrown at runtime

  • 16. 
    Which are true?
    • A. 

      Encapsulation limits the consequences of change.

    • B. 

      Encapsulation makes it easier to reuse classes.

    • C. 

      Encapsulation results in better testing and higher reliability.

    • D. 

      Encapsulation means that methods are all public.

    • E. 

      Encapsulation means that classes are members of packages.

  • 17. 
    Class X{void go(){System.out.print("x");}}class Y extends X{void go(){System.out.print("y");}}class Z extends X{void go(){System.out.print("z");}}class Chrome1{public static void main(String[] args){X z=new Z();X y=new Y();Z y2=(Z)y;y.go();y2.go();}}what is the result?
    • A. 

      Xxx

    • B. 

      Xxz

    • C. 

      Zyy

    • D. 

      Zyz

    • E. 

      An exception is thrown at runtime

  • 18. 
    Public class Felix{ protected long cat(){return 7L;}}class Oscar extends Felix{//insert code here} which method inserted ,will compile?
    • A. 

      Private long cat(int x){return 7;}

    • B. 

      Public long cat(){return 7;}

    • C. 

      Long cat(){return 7;}

    • D. 

      Protected int cat(int x){return 7;}

    • E. 

      None of these

  • 19. 
    Which of the following are legal definitions for non-nested classes and interfaces?
    • A. 

      Static public interface Foo{}

    • B. 

      Abstract public class Foo{}

    • C. 

      Protected interface Foo{}

    • D. 

      Final abstract class Foo{}

    • E. 

      Final public class Foo{}

  • 20. 
    Public class Switch2{public static void main(String[] args){int y=0;for(int x=3;x>=0;x--){switch(x){case 3:y=y+100;case 2:y=y+10;case 1:break;case 0:y=y+1;}}System.out.println(y);}}what is the result?
    • A. 

      120

    • B. 

      121

    • C. 

      122

    • D. 

      123

    • E. 

      Compilation fails

  • 21. 
    Public static void main(String[] args){TreeSet<Number> tree=new TreeSet<Number>();tree.add(108);//insert here}which is inserted to compile and run
    • A. 

      Tree.add(3.14);

    • B. 

      Tree.add("42");

    • C. 

      Tree.add(Integer.valueOf("-1"));

    • D. 

      Tree.add(null);

    • E. 

      Tree.add(0xCAFE)

  • 22. 
    Calss Bulbs{ enum Turn{  ON("bright"),OFF("dark");}public staticmvoid main(String[] args){ System.out.println(Turn.ON);}}what is the result?
    • A. 

      ON

    • B. 

      Bright

    • C. 

      Compilation fails

    • D. 

      No output is produced

    • E. 

      Exception

  • 23. 
    Which is true?
    • A. 

      It is not good practice to place assertions where you think execution should never reach.

    • B. 

      It is sometimes appropriate to call getters and setters from assertions.

    • C. 

      Use assertions to verify the arguments of private methods.

    • D. 

      Assertions can be disabled for a particular class

    • E. 

      Never throw an AssertionError explicitly

  • 24. 
    Class Battery{static int x=1;public static void main(String[] args) throws Throwable{try{if(x==1)throw new Throwable();System.out.println("try");}catch(Exception e){System.out.println("exc");}finally{System.out.println("fin");}}}what is the result?
    • A. 

      Try

    • B. 

      Try fin

    • C. 

      Exc fin

    • D. 

      Fin then a runtime exception

    • E. 

      Compilation fails

  • 25. 
    Which of the following can be constructed using a String?
    • A. 

      Java.io.File

    • B. 

      Java.io.FileWriter

    • C. 

      Java.io.PrintWriter

    • D. 

      Java.io.FileReader

    • E. 

      Java.io.BufferedWriter

Back to Top Back to top
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.