well ,here's your chance to test your skills in java.These questions were taken from a test that was conducted by my college.I recommend you to try it. Attempt it just like an online exam and try to complete it within 35 min.I won't be updating answers coz u know where to look for it.
1.Which four options describe the correct default values for array elements of the types indicated?
1. int -> 0
2. String -> "null"
3. Dog -> null
4. char -> '\u0000'
5. float -> 0.0f
6. boolean -> true
A.1, 2, 3, 4
B.1, 3, 4, 5
C.2, 4, 5, 6
D.3, 4, 5, 6
2.Which one of these lists contains only Java programming language keywords?
A.class, if, void, long, Int, continue
B.goto, instanceof, native, finally, default, throws
C.try, virtual, throw, final, volatile, transient
D.strictfp, constant, super, implements, do
E.byte, break, assert, switch, include
3.Which will legally declare, construct, and initialize an array?
A.int [] myList = {"1", "2", "3"};
B.int [] myList = (5, 8, 2);
C.int myList [] [] = {4,9,7,0};
D.int myList [] = {4, 3, 7};
4.Which is a reserved word in the Java programming language?
A.method
B.native
C.subclasses
D.reference
E.array
5.Which is a valid keyword in java?
A.interface
B.string
C.Float
D.unsigned
6.Which three are legal array declarations?
1. int [] myScores [];
2. char [] myChars;
3. int [6] myScores;
4. Dog myDogs [];
5. Dog myDogs [7];
7.Which three piece of codes are equivalent to line 3?
public interface Foo
{
int k = 4; /* Line 3 */
}
1. final int k = 4;
2. public int k = 4;
3. static int k = 4;
4. abstract int k = 4;
5. volatile int k = 4;
6. protected int k = 4;
8.What will be the output of the program?
public class MyProgram
{
public static void main(String args[])
{
try
{
System.out.print("Hello world ");
}
finally
{
System.out.println("Finally executing ");
}
}
}
A.Nothing. The program will not compile because no exceptions are specified.
B.Nothing. The program will not compile because no catch clauses are specified.
C.Hello world.
D.Hello world Finally executing
9.What will be the output of the program?
class Exc0 extends Exception { }
class Exc1 extends Exc0 { } /* Line 2 */
public class Test
{
public static void main(String args[])
{
try
{
throw new Exc1(); /* Line 9 */
}
catch (Exc0 e0) /* Line 11 */
{
System.out.println("Ex0 caught");
}
catch (Exception e)
{
System.out.println("exception caught");
}
}
}
A.Ex0 caught
B.exception caught
C.Compilation fails because of an error at line 2.
D.Compilation fails because of an error at line 9.
10.What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod(); /* Line 7 */
System.out.print("A");
}
catch (Exception ex) /* Line 10 */
{
System.out.print("B"); /* Line 12 */
}
finally /* Line 14 */
{
System.out.print("C"); /* Line 16 */
}
System.out.print("D"); /* Line 18 */
}
public static void badMethod()
{
throw new RuntimeException();
}
}
A.AB
B.BC
C.ACD
D.BCD
11.What will be the output of the program?
public class Test
{
public static void aMethod() throws Exception
{
try /* Line 5 */
{
throw new Exception(); /* Line 7 */
}
finally /* Line 9 */
{
System.out.print("finally "); /* Line 11 */
}
}
public static void main(String args[])
{
try
{
aMethod();
}
catch (Exception e) /* Line 20 */
{
System.out.print("exception ");
}
System.out.print("finished"); /* Line 24 */
}
}
A.finally
B.exception finished
C.finally exception finished
D.Compilation fails
12.What will be the output of the program?
public class RTExcept
{
public static void throwit ()
{
System.out.print("throwit ");
throw new RuntimeException();
}
public static void main(String [] args)
{
try
{
System.out.print("hello ");
throwit();
}
catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
}
System.out.println("after ");
}
}
A.hello throwit caught
B.Compilation fails
C.hello throwit RuntimeException caught after
D.hello throwit caught finally after
13.What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (RuntimeException ex) /* Line 10 */
{
System.out.print("B");
}
catch (Exception ex1)
{
System.out.print("C");
}
finally
{
System.out.print("D");
}
System.out.print("E");
}
public static void badMethod()
{
throw new RuntimeException();
}
}
A.BD
B.BCD
C.BDE
D.BCDE
14.What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod()
{
throw new Error(); /* Line 22 */
}
}
A.ABCD
B.Compilation fails.
C.C is printed before exiting with an error message.
D.BC is printed before exiting with an error message.
15.What will be the output of the program?
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");
16.What will be the output of the program?
public class Foo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
A.Finally
B.Compilation fails.
C.The code runs with no output.
D.An exception is thrown at runtime.
17.which statement, inserted at line 10, creates an instance of Bar?
class Foo{
class Bar{ }
}
class Test
{
public static void main (String [] args)
{
Foo f = new Foo();
/* Line 10: Missing statement ? */
}
}
A.Foo.Bar b = new Foo.Bar();
B.Foo.Bar b = f.new Bar();
C.Bar b = new f.Bar();
D.Bar b = f.new Bar();
18.Which constructs an anonymous inner class instance?
A.Runnable r = new Runnable() { };
B.Runnable r = new Runnable(public void run() { });
C.Runnable r = new Runnable { public void run(){}};
D.System.out.println(new Runnable() {public void run() { }});
19.Which statement is true about a static nested class?
A.You must have a reference to an instance of the enclosing class in order to instantiate it.
B.It does not have access to nonstatic members of the enclosing class.
C.It's variables and methods must be static.
D.It must extend the enclosing class.
20.Which is true about a method-local inner class?
A.It must be marked final.
B.It can be marked abstract.
C.It can be marked public.
D.It can be marked static.
21.which one create an anonymous inner class from within class Bar?
class Boo{
Boo(String s) { }
Boo() { }
}
class Bar extends Boo
{
Bar() { }
Bar(String s) {super(s);}
void zoo()
{
// insert code here
}
}
A.Boo f = new Boo(24) { };
B.Boo f = new Bar() { };
C.Bar f = new Boo(String s) { };
D.Boo f = new Boo.Bar(String s) { };
22.Which is true about an anonymous inner class?
A.It can extend exactly one class and implement exactly one interface.B.It can extend exactly one class and can implement multiple interfaces.
C.It can extend exactly one class or implement exactly one interface.
D.It can implement multiple interfaces regardless of whether it also extends a class.
23.What is the numerical range of a char?
A.-128 to 127B.-(215) to (215) - 1
C.0 to 32767
D.0 to 65535
24.Which is a valid declarations of a String?
A.String s1 = null;B.String s2 = 'null';
C.String s3 = (String) 'abc';
D.String s4 = (String) '\ufeed';
25.Which three are valid declarations of a float?
1. float f1 = -343;2. float f2 = 3.14;
3. float f3 = 0x12345;
4. float f4 = 42e7;
5. float f5 = 2001.0D;
6. float f6 = 2.81F;
If you have any doubts regarding the Questions then post your comment in comments section below .

0 comments:
Post a Comment