Your Ad Here

Friday

0 Odesk Java Test Answers



1) Can you compare a boolean to an integer?      
  a) Yes        b) No 


2) Following code will result in: int a = 9/0;     
   a) Compilation error: Divisions must be in a try block.        b) Compilation error: DivideByZeroException        c) Runtime Exception         d) No Error: a is NaN

3) A class can be transient     
   a) True        b) False 

4) 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 

5) A class cannot be declared:      
  a) Static        b) Private         c) Default

6) Following code will result in: float a = 9/0;       
 a) Compilation error: Divisions must be in a try block        b) Compilation error: DivideByZeroException        c) Runtime Exception       d) No Error: a is NaN

7) Following code will result in: int a = 3.5;  
      a) Compilation error        b) Runtime error        c) a being 3.5        d) a being 3.

8) 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) Output of b is 1

9) 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

10) ) Following code will result in: int a1 = 5; double a2 = (float)a1;      
  a) Compilation error        b) Runtime error        c) No errors

11) Methods that are marked protected can be called in any subclass of that class.      
  a) True        b) False

12) An abstract class can have non-abstract methods.    
    a) True       b) False

13) Java keywords are written in lowercase as well as uppercase.       
a) True        b) False 

14) What is an instanceof        a) A methods in object     
   b) An operator and keyword 

15) Primitive datatypes are allocated on a stack.     
   a) True         b) False

16) What is the size of a Char?       

 a) 4 bits        b) 7 bits        c) 8 bits        d) 16 bits 

17) 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 

18) The default statement of a switch is always executed.      
  a) True        b) False 

19) The methods wait(), notify() and notifyAll() in Object need to be called from synchronized pieces of code.      
  a) True         b) False

20) Inner classes can be defined within methods.     
   a) True        b) False

21) Synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution.      
  a) True      b) False

22) 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 


23) How can you prevent a member variable from becoming serialized?    
    a) By marking it private        b) By marking it volatile        c) By marking it transient         d) You can not.

24)  For the given variables, which of the following will compile without an error?char c = 'c';
int i = 50; double d = 80; long l = 200; String s = "Goodbye";
   a)s+=i;     b)  i+=s     c) c+=s     d) c=c+i

25) Which of the following are "keywords" in Java?
    a) default  b) Null   c) String  d) throws

26) What will be the output when this code is compiled and run?.    
public class Test
{
static int x = 10;
public Test ()
{
Bar b = new Bar ();
Bar b1 = new Bar ();
update (b);
update (b1);
}
private void update (Bar bar)
{
bar.x = ++x;
System.out.println (bar.x);
}
public static void main (String args[])
{
File f = new File("/","autoexec.bat");
 b.DataInputStream d = new DataInputStream(System.in);
c.RandomAccessFile r = new RandomAccessFile("OutFile");
d.OutputStreamWriter o = newOutputStreamWriter(System.out);
}
private class Bar
{
public int x = 10;
}
   a) The code will to fail      b) 11 12     c) 11 11   d)12 12



0 comments:

Post a Comment

 

Free Test Answers And Blogger Tips For Making Money Online Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates