Guest | Sign in | Register

Sign in to LucentBlackBoard

E-mail Id
Password
Loading...

New Member to LucentBlackBoard?

Forgot Your Password?

Enter your registered e-mail address, your password will be sent to e-mail address.
Enter E-mail Id
Loading...

Time left :





Note:

1. Total number of questions : 15.

2. Time alloted : 20 minutes.

3. Each question carry 1 mark, no negative marks.

4. Click the 'Submit Test' button given in the bottom of this page to Submit your answers.

5. Test will be submitted automatically if the time expired.

6. Don't refresh the page.

Result and Statistics

Time Left :

Result and Statistics ( Test No : online_test_number )

A. Number Of Question

15

B. Number Of Attempted

-

C. Number Of Correct Answer

-

D. Number Of Wrong Answer ( D = B-C )

-

E. Total Score ( E = C )

-

F. Accuracy Rate ( F = C / B * 100 )

-

G. Total Percentage ( G = C / A * 100 )

-



1.

Given:
abstract class C1 {
public C1() { System.out.print(1); }
}
class C2 extends C1 {
public C2() { System.out.print(2); }
}
class C3 extends C2 {
public C3() { System.out.println(3); }
}
public class Ctest {
public static void main(String[] a) { new C3(); }
}

class C3 extends C2 {
public C3() { System.out.println(3); }
}
public class Ctest {
public static void main(String[] a) { new C3(); }
}


What is the result?

A.    3 Wrong Right

B.    23 Wrong Right

C.    32 Wrong Right

D.    123 Wrong Right

Answer : 123

Explanation : All constructors are executed in order top (C1) to bottom (C3)

Learn more problems on : Abstract

Discuss on this question

2.

What is the output for the below code ?

public class Test {
public static void main(String... args) {
for(int i = 2; i < 4; i++)
for(int j = 2; j < 4; j++)
if(i < j)
assert i!=j : i;
}
}

A.    The class compiles and runs, but does not print anything. Wrong Right

B.    The number 2 gets printed with AssertionError Wrong Right

C.    The number 3 gets printed with AssertionError Wrong Right

D.    compile error Wrong Right

Answer : The class compiles and runs, but does not print anything.

Explanation : When if condition returns true, the assert statement also returns true.
Hence AssertionError not generated.

Learn more problems on : Assertions

Discuss on this question

3.

1. Object [] myObjects = {
2. new Integer(12),
3.  new String("foo"),
4.      new Integer(5),
5.      new Boolean(true)
6. };
7. Arrays.sort(myObjects);
8. for(int i=0; i9. System.out.print(myObjects[i].toString());
10  System.out.print(" ");
11. }
What is the result?

A.    Compilation fails due to an error in line 1. Wrong Right

B.    Compilation fails due to an error in line 7. Wrong Right

C.    A ClassCastException occurs in line 7. Wrong Right

D.    A ClassCastException occurs in line 9. Wrong Right

E.    The value of all four objects prints in natural order. Wrong Right

Answer : A ClassCastException occurs in line 7.

Explanation : Whenever you call Arrays.sort() method on some object then that class should implement Comparable interface. If not it will throw exception.

Learn more problems on : Collections

Discuss on this question

4.

class A{
public static void main(String args[]){
try{
System.out.println(“one”); 

}
System.out.println(“four”);
catch(Exception e){
System.out.println(“two”);
}finally{
System.out.println(“three”); }
}
}

A.    one ,four , two , three Wrong Right

B.    one , four , three Wrong Right

C.    one , three Wrong Right

D.    compile time error Wrong Right

Answer : compile time error

Explanation : In any program as soon as you complete try block you have to start catch block or finally block, in between if you try to write anything it will throw compile time error.

Learn more problems on : Exceptions

Discuss on this question

5.


public class A implements Serializable{
public A() {
System.out.println("A");
}
}
public class Test {
public static void main(String... args) throws Exception {
A a = new A();
ObjectOutputStream save = new ObjectOutputStream(new FileOutputStream("datafile"));
save.writeObject(a);
save.flush();
ObjectInputStream restore = new ObjectInputStream(new FileInputStream("datafile"));
A z = (A) restore.readObject();
}
}

A.    A Wrong Right

B.    A A Wrong Right

C.    Runtime Exception Wrong Right

D.    Compile with error Wrong Right

Answer : A

Explanation : On the time of deserialization , the Serializable object not create new object. So
constructor of class A does not called.

Learn more problems on : File

Discuss on this question

6.

Class F
{
Static void test(int I,int j){
System.out.println(“integer”);
}
Static void test(byte …b){
System.out.println(“byte”);
}

Public static void main(String args[]){
byte s=10;
test(s,s);
}
}

A.    compile time error Wrong Right

B.    runtime error Wrong Right

C.    byte Wrong Right

D.    0 Wrong Right

Answer : byte

Explanation : Byte…b is called var-args(variable arguments).from main() when we call test(s,s) then test(byte…b) will execute.. to call test(byte…b) you can pass any number of parameters, but it should be of type byte as per the above example.

Learn more problems on : Final and Datatypes

Discuss on this question

7.

class F{
static void main(String args[]){
System.out.println(“HI”);
}
}

A.    compile time error Wrong Right

B.    run time error Wrong Right

C.    HI Wrong Right

D.    no output Wrong Right

Answer : run time error

Explanation : here public keyword is removed from main() method signature, compiler will check whether main() method is declared properly or not , According to the compiler its correct, because public access specifier is not a mandatory for all the methods, its upto the developer to decide when to use public and all . BUT during runtime JVM will check the signature of main() method , but its wrong, because JVM will be searching for the method

Learn more problems on : Flow Control

Discuss on this question

8.

public class A {
public void test1(){
System.out.println("test1");
}
}
public class B extends A{
public void test2(){
System.out.println("test2");
}
}
1. public class Test{
2. public static void main (String[] args){
3. A a = new A();
4. A b = new B();
5. B b1 = new B();
6. // insert code here
7. }
8. }

Which of the following , inserted at line 6, will compile and print
test2?

A.    ((B)b).test2(); Wrong Right

B.    (B)b.test2(); Wrong Right

C.    b.test2(); Wrong Right

D.    a.test2(); Wrong Right

Answer : ((B)b).test2();

Explanation : ((B)b).test2(); is proper cast. test2() method is in class B so need to cast b then only
test2() is accessible. (B)b.test2(); is not proper cast without the second set of parentheses,the compiler thinks it is an incomplete statement.

Learn more problems on : Inheritance

Discuss on this question

9.

Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d?

A.    (int)Math.min(d); Wrong Right

B.    (int)Math.max(d); Wrong Right

C.    (int)Math.abs(d); Wrong Right

D.    (int)Math.floor(d); Wrong Right

Answer : (int)Math.floor(d);

Explanation : The casting to an int is a smokescreen. Use a process of elimination to answer this question:
Option D is the correct answer, it is syntathecially correct and will consistently return a value less than d.
Option A and B are wrong because both the min() and max() methods require 2 arguments whereas here they are passed only one parameter.
Option C is wrong because it could return a value greater than d (if d was negative).

Learn more problems on : java.lang.class

Discuss on this question

10.

class A{

Static{
Main(null);}
Public static void main(String args[]){
System.out.println(“main”);}
}

A.    compile time error Wrong Right

B.    runtime error Wrong Right

C.    main main  Wrong Right

D.    exception Wrong Right

Answer : main main 

Explanation : Explanation: here we have declared SIB(static initialization block), JVM always executes SIB first before the main() method , then it executes main() method, here from SIB they are calling main() method by passing null as parameter so because of calling main() in SIB it displays “main” , then JVM executes main() method so again “main” will be displayed . so ans c) is correct.

Learn more problems on : Static Concept

Discuss on this question

11.

class A{

Static{
String all[]=new String[0];
Main(null);
}
Public static void main(String args[]){
System.out.println(“main”);}
}

A.    compile time error Wrong Right

B.    runtime error Wrong Right

C.    main main  Wrong Right

D.    exception Wrong Right

Answer : main main 

Explanation : here we have declared SIB(static initialization block), JVM always executes SIB first before the main() method , then it executes main() method,they have declared string array with size 0, in 0th position null will be stored. here from SIB they are calling main() method by passing null as parameter so because of calling main() in SIB it displays “main” , then JVM executes main() method so again “main” will be displayed . so ans c) is correct.

Learn more problems on : Static Concept

Discuss on this question

12.

 What will happen when you attempt to compile and run the following code?


class A implements Runnable{
public void run(){
System.out.println("run-A");
}
}
1. public class Test {
2. public static void main(String argv[]){
3. A a = new A();
4. Thread t = new Thread(a);
5. System.out.println(t.isAlive());
6. t.start();
7. System.out.println(t.isAlive());
8. }
9. }

A.    false run-A true Wrong Right

B.    false run-A false Wrong Right

C.    true run-A true Wrong Right

D.    Compilation fails due to an error on line 7 Wrong Right

Answer : false run-A true

Explanation : Once the start() method is called, the thread is considered to be alive.

Learn more problems on : Threads

Discuss on this question

13.

What happens when the following code is compiled and run.


Select the one correct answer.
for(int i = 2; i < 4; i++)
for(int j = 2; j < 4; j++)
if(i < j)
assert i!=j : i;

A.    The class compiles and runs, but does not print anything Wrong Right

B.    The number 2 gets printed with AssertionError Wrong Right

C.    compile error Wrong Right

D.    The number 3 gets printed with AssertionError Wrong Right

Answer : The class compiles and runs, but does not print anything

Explanation : When if condition returns true, the assert statement also returns true. Hence
AssertionError does not get generated. .

Learn more problems on : Variables and Loops

Discuss on this question

14.

  What is the result of trying to compile and run this program.
public class Test{
public static void main(String[] args){
int[] a = {1};
Test t = new Test();
t.increment(a);
System.out.println(a[a.length - 1]);
}
void increment(int[] i){
i[i.length - 1]++;
}
}

A.    Compiler error. Wrong Right

B.    Compiles and runs printing out 2
Wrong Right

C.    Compiles and runs printing out 1
Wrong Right

D.    An ArrayIndexOutOfBounds Exception at runtime Wrong Right

Answer : Compiles and runs printing out 2

Explanation :  You are passing a reference to an array as
the argument to the method. The method may not
modify the passed object reference but it can modify
the object itself.  

Learn more problems on : Language Fundamentals

Discuss on this question

15.

What will be the result of compiling and run the following code:
public class Test {
public static void main(String... args) throws Exception {
Object o = new Object() {
public boolean equals(Object obj) {
return true;
}
}
System.out.println(o.equals("test"));
}
}

A.    Compile Fail: semicolon missing at Object o = new Object() { public boolean
equals(Object obj) { return true; } };
Wrong Right

B.    test Wrong Right

C.    Compilation succeed but Runtime Exception Wrong Right

D.    None of the above Wrong Right

Answer : Compile Fail: semicolon missing at Object o = new Object() { public boolean
equals(Object obj) { return true; } };

Explanation : semicolon missing at Object o = new Object() { public boolean equals(Object obj)
{ return true; } };

Learn more problems on : Inner Classes

Discuss on this question

Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved 2012-2015 SoftLucent.