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.

abstract class Vehicle {
public int speed() { return 0; }
class Car extends Vehicle { public int speed() { return 60; }
class RaceCar extends Car { public int speed() { return 150; } ...
RaceCar racer = new RaceCar();
Car car = new RaceCar();
Vehicle vehicle = new RaceCar();
System.out.println(racer.speed() + ", " + car.speed() + ", " + vehicle.speed());
}

What is the result?

A.    0, 0, 0 Wrong Right

B.    150, 60, 0 Wrong Right

C.    Compilation fails. Wrong Right

D.    150, 150, 150 Wrong Right

E.    An exception is thrown at runtime. Wrong Right

Answer : 150, 150, 150

Explanation : just normal flow of execution.

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++)
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 number 2 gets printed with AssertionError

Explanation : When i and j are both 2, assert condition is false, and AssertionError gets generated. 

Learn more problems on : Assertions

Discuss on this question

3.

1. HashMap props = new HashMap();
2. props.put("key45", "some value");
3. props.put("key12", "some other value");
4. props.put("key39", "yet another value");
5. Set s = props.keySet();
6. // insert code here
What, inserted at line 6, will sort the keys in the props HashMap?

A.    Arrays.sort(s); Wrong Right

B.    s = new TreeSet(s); Wrong Right

C.    Collections.sort(s); Wrong Right

D.    s = new SortedSet(s); Wrong Right

Answer : s = new TreeSet(s);

Explanation : If you store HashMap values into TreeSet then values will get sorted automatically,so here we are storing HashMap values into TreeSet. 

Learn more problems on : Collections

Discuss on this question

4.

Given:

1. // some code here
2. try{
3. // some code here
4.} catch (SomeException se) {
5. // some code here
6.} finally {
7. // some code here
8.}

Under which three circumstances will the code on line 7 be executed? (Choose three.)

A. The instance gets garbage collected.
B. The code on line 3 throws an exception.
C. The code on line 5 throws an exception.
D. The code on line 1 throws an exception.
E. The code on line 3 executes successfully.

A.    A,B,C Wrong Right

B.    B,C,E Wrong Right

C.    A,B,E Wrong Right

D.    C,D,E Wrong Right

Answer : B,C,E

Explanation : When finally block will execute, as we know if no exception occurs (means in 3 line) then directly finally block will execute.
If exception occurs then try, catch, finally (means line 3 as well as 5) block will execute.
Or else directly after 1 line finally block will execute.
So A) is correct.

Learn more problems on : Exceptions

Discuss on this question

5.

public class A {
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();
}
}

What is the output?

A.    A A Wrong Right

B.    A Wrong Right

C.     java.io.NotSerializableException Wrong Right

D.    None of the above Wrong Right

Answer :  java.io.NotSerializableException

Explanation : Class A does not implements Serializable interface. So throws
NotSerializableException on trying to Serialize a non Serializable object.

Learn more problems on : File

Discuss on this question

6.

Class w{
Public static void main(String agrs[]){
System.out.println(“hello”);
}

Public static void main(String agrs[]){
System.out.println(“hello”);
}

}

A.    hello Wrong Right

B.    compile time error Wrong Right

C.    runtime error Wrong Right

D.    none of the above Wrong Right

Answer : compile time error

Explanation : Duplicate main() method. In a single class we cant have two main() methods..

Learn more problems on : Final and Datatypes

Discuss on this question

7.

class F
{
public 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 static 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 static keyword is not a mandatory for all the methods, its upto the developer to decide when to use static and all . BUT during run time JVM will check the signature of main() method , but its wrong, because JVM will be searching for the method which has public static void main(), so it will throw run time error. 

Learn more problems on : Flow Control

Discuss on this question

8.

What is the output for the below code ?


public class A {
public A(){
System.out.println("A");
}
public A(int i){
this();
System.out.println(i);
}
}
public class B extends A{
public B (){
System.out.println("B");
}
public B (int i){
this();
System.out.println(i+3);
}
}
public class Test{
public static void main (String[] args){
new B(5);
}
}

A.    A B 8 Wrong Right

B.    A 5 B 8 Wrong Right

C.    A B 5 Wrong Right

D.    B 8 A 5 Wrong Right

Answer : A B 8

Explanation : Constructor of class B call their superclass constructor of class A (public A()) , which
execute first, and that constructors can be overloaded. Then come to constructor of class B (public B (int i)).

Learn more problems on : Inheritance

Discuss on this question

9.

which three can be included in an interface declaration?

A.    void showmessage();

public void showmessage();
private void showmessage();
Wrong Right

B.    public void showmessage();

static void showmessage();
abstract void showmessage();
Wrong Right

C.    void showmessage();
public void showmessage();
abstract void showmessage(); Wrong Right

D.    static void showmessage();
private void showmessage();
abstract void showmessage(); Wrong Right

Answer : void showmessage();
public void showmessage();
abstract void showmessage();

Explanation : all the methods in an interface are by default public abstract, even if you don’t specify by default it will be public abstract

Learn more problems on : Interface

Discuss on this question

10.

class W{
Static void method(Byte I,Byte j ){
System.out.println(“BByte”); }
Static void method(byte…b){
System.out.println(“byte”); }

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

A.    compile time error Wrong Right

B.    runtime error Wrong Right

C.    int Wrong Right

D.    byte Wrong Right

Answer : int

Explanation : while calling method() from main() we are passing exactly two parameter as byte , as we are calling by passing only byte that to as primitive type it display output as byte.

Learn more problems on : Objects and Collections

Discuss on this question

11.

class c{
Int I;
Static void test1()
{
System.out.println(“test1”);
}
Static void tes2t()
{
System.out.println(“test1”);
}

}

A.    compile time error Wrong Right

B.    runtime exception Wrong Right

C.    test1 test2  Wrong Right

D.    no output Wrong Right

Answer : runtime exception

Explanation : here we declared static method not SIB, JVM try to execute but there is no main() method so it will throw runtime exception

Learn more problems on : Static Concept

Discuss on this question

12.

Which of the following statements about this code are true?

class A extends Thread{
public void run(){
for(int i =0; i < 2; i++){
System.out.println(i);
}
}
}
public class Test{
public static void main(String argv[]){
Test t = new Test();
t.check(new A(){});
}
public void check(A a){
a.start();
}
}

A.    0 0 Wrong Right

B.    Compilation error, class A has no start method Wrong Right

C.    0 1 Wrong Right

D.    Compilation succeed but runtime exception Wrong Right

Answer : 0 1

Explanation : class A extends Thread means the anonymous instance that is passed to check() method has a start method which then calls the run method.

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++)
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 number 2 gets printed with AssertionError

Explanation : When i and j are both 2, assert condition is false, and AssertionError gets generated. .

Learn more problems on : Variables and Loops

Discuss on this question

14.

Which of the following are valid declarations?

Note : None of the literals used here
contain the character O they are all zeroes.

1. int i = 0XCAFE;
2. boolean b = 0;
3. char c = 'A';
4. byte b = 128;
5. char c = "A";

A.    1,2 Wrong Right

B.    1,4 Wrong Right

C.    2,4 Wrong Right

D.    4,5 Wrong Right

E.    1,3 Wrong Right

Answer : 1,3

Explanation : 1. is correct as it is a valid hexadecimal number.2. is wrong
because you can only assign the values true and false to them
4 is wrong because 128 is beyond the range of a byte. 5is wrong
because "A" is not a char it is a String. 

Learn more problems on : Language Fundamentals

Discuss on this question

15.

Which are true about an anonymous inner class?

A.    can extend exactly one class and implement exactly one interface Wrong Right

B.    can extend exactly one class or implement exactly one interface. Wrong Right

C.    can implement multiple interfaces if it does not extend a class. Wrong Right

D.    can implement multiple interfaces if it does not extend a class. Wrong Right

Answer : can extend exactly one class or implement exactly one interface.

Explanation : syntax of an anonymous inner class allows for only one. can extend exactly one class or implement exactly one interface. Ianimal c = new Ianimal() { } Ianimal can be
class or interface.

Learn more problems on : Inner Classes

Discuss on this question

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