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 Foo {
Foo () {}
}

Can we declare a constructor in an abstract class? 

A.    Yes Wrong Right

B.    No Wrong Right

C.    Cannot be determined Wrong Right

D.    None of the above Wrong Right

Answer : Yes

Explanation : We can declare a constructor in an abstract class.

Learn more problems on : Abstract

Discuss on this question

2.

What will be the output of the program (when you run with the -ea option) ?
public class Test{
public static void main(String[] args){
int x = 0;
assert (x > 0) : "assertion failed"; /* Line 6 */
System.out.println("finished");
}
}

A.    finished Wrong Right

B.    Compilation fails. Wrong Right

C.    An AssertionError is thrown. Wrong Right

D.    An AssertionError is thrown and finished is output. Wrong Right

Answer : An AssertionError is thrown.

Explanation : An assertion Error is thrown as normal giving the output "assertion failed". The word "finished" is not printed (ensure you run with the -ea option)
Assertion failures are generally labelled in the stack trace with the file and line number from which they were thrown, and also in this case with the error's detail message "assertion failed". The detail message is supplied by the assert statement in line 6.

Learn more problems on : Assertions

Discuss on this question

3.

1. import java.util.*;
2. public class Old {
3. public static Object get0(List list) {
4. return list.get(0);
5. }
6. }


Which three will compile successfully? (Choose three.)
A. Object o = Old.get0(new LinkedList());
B. Object o = Old.get0(new LinkedList());
C. String s = Old.get0(new LinkedList());
D. Object o = Old.get0(new LinkedList());
E. String s = (String)Old.get0(new LinkedList());

A.    A,B,C Wrong Right

B.    A,D,E Wrong Right

C.    A,B,D Wrong Right

D.    C,D,E Wrong Right

Answer : A,D,E

Explanation : Just normal flow of execution.

Learn more problems on : Collections

Discuss on this question

4.

What will be the output of the program?
import java.util.*;
public class NewTreeSet2 extends NewTreeSet{
public static void main(String [] args){
NewTreeSet2 t = new NewTreeSet2();
t.count();
}
}
protected class NewTreeSet{
void count(){
for (int x = 0; x < 7; x++,x++ ){
System.out.print(" " + x);
}
}
}

A.    0 2 4 6 Wrong Right

B.    0 2 4 Wrong Right

C.    Compilation fails at line 10 Wrong Right

D.    Compilation fails at line 2 Wrong Right

Answer : Compilation fails at line 10

Explanation : Non-nested classes cannot be marked protected (or final for that matter), so the compiler will fail at protected class NewTreeSet.

Learn more problems on : Declarations and Access Control

Discuss on this question

5.

class A{
public static void main(String args[]){
try{
System.out.println(“one”);
System.exit(0);
}catch(Exception e){
System.out.println(“two”); }
finally{
System.out.println(“three”); 

}
}
}

A.    one , two , three Wrong Right

B.    one , three Wrong Right

C.    one   Wrong Right

D.    compile time error Wrong Right

Answer : one  

Explanation : In the above program inside a try block they have used System.exit(0), if you use this code then rest of the code will get skipped from the execution.
So c) is correct answer.

Learn more problems on : Exceptions

Discuss on this question

6.

Public class Manager{
Static final String name;
Static{
name=”lara”;
}
Public static void main(String args[]){
System.out.println(name.length()); } }

A.    0 Wrong Right

B.    null Wrong Right

C.    compile time error Wrong Right

D.    4 Wrong Right

Answer : 4

Explanation : final variable is initialized in a static block. So it will not throw any error.

Learn more problems on : Final and Datatypes

Discuss on this question

7.

What will be the output of the program?


int i = O;
while(1)
{
if(i == 4)
{
break;
}
++i;
}
System.out.println("i = " + i);

A.    i = 0 Wrong Right

B.    i = 3 Wrong Right

C.    i = 4 Wrong Right

D.    Compilation fails. Wrong Right

Answer : Compilation fails.

Explanation : Compilation fails because the argument of the while loop, the condition, must be of primitive type boolean. In Java, 1 does not represent the true state of a boolean, rather it is seen as an integer.

Learn more problems on : Flow Control

Discuss on this question

8.

class A{
int I;
A(){
System.out.println(1);
} }


Class B extends A{
B(int i){
System.out.println(2);
This.i=I;
}}

Class Manager{
Public static void main(String args[]){
B b1=new B(20);
System.out.println(b1.i);} }

A.    1,2,20 Wrong Right

B.    20,2,1 Wrong Right

C.    compile time error Wrong Right

D.    run time error Wrong Right

Answer : 1,2,20

Explanation : in main() method we are creating an object of class B by calling B class constructor, class B constructor will call super class constructor because in each constructor body super() keyword will be there by default, so first class A constructor will execute then class B constructor finally main() method. So ans a)is correct

Learn more problems on : Inheritance

Discuss on this question

9.

2. What will be the output of the program?


public class ObjComp
{
public static void main(String [] args )
{
int result = 0;
ObjComp oc = new ObjComp();
Object o = oc;

if (o == oc)
result = 1;
if (o != oc)
result = result + 10;
if (o.equals(oc) )
result = result + 100;
if (oc.equals(o) )
result = result + 1000;

System.out.println("result = " + result);
}
}

A.    1 Wrong Right

B.    10 Wrong Right

C.    101 Wrong Right

D.    1101 Wrong Right

Answer : 1101

Explanation : Even though o and oc are reference variables of different types, they are both referring to the same object. This means that == will resolve to true and that the default equals() method will also resolve to true.

Learn more problems on : java.lang.class

Discuss on this question

10.

What will be the output of the program?
public class Test
{
public static void main (String args[])
{
String str = NULL;
System.out.println(str);
}
}

A.    NULL Wrong Right

B.    Compile Error Wrong Right

C.    Code runs but no output Wrong Right

D.    Runtime Exception Wrong Right

Answer : Compile Error

Explanation : Option B is correct because to set the value of a String variable to null you must use "null" and not "NULL".

Learn more problems on : Objects and Collections

Discuss on this question

11.

What will be the output of the program?
class PassS
{
public static void main(String [] args)
{
PassS p = new PassS();
p.start();
}

void start()
{
String s1 = "slip";
String s2 = fix(s1);
System.out.println(s1 + " " + s2);
}

String fix(String s1)
{
s1 = s1 + "stream";
System.out.print(s1 + " ");
return "stream";
}
}

A.    slip stream Wrong Right

B.    slipstream stream Wrong Right

C.    stream slip stream Wrong Right

D.    slipstream slip stream Wrong Right

Answer : slipstream slip stream

Explanation : When the fix() method is first entered, start()'s s1 and fix()'s s1 reference variables both refer to the same String object (with a value of "slip"). Fix()'s s1 is reassigned to a new object that is created when the concatenation occurs (this second String object has a value of "slipstream"). When the program returns to start(), another String object is created, referred to by s2 and with a value of "stream".

Learn more problems on : Operators and Assignments

Discuss on this question

12.

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

A.    first

main
Wrong Right

B.    main
first
Wrong Right

C.    compile time error Wrong Right

D.    runtime error Wrong Right

Answer : first

main

Explanation : here we have declared SIB(static initialization block), JVM always executes SIB first , then main() method , then it executes main() method, so ans a) is correct.

Learn more problems on : Static Concept

Discuss on this question

13.

class A {
A(String s) {
}
A() {
}
}
1. class B extends A {
2. B() { }
3. B(String s) {
4. super(s);
5. }
6. void test() {
7. // insert code here
8. }
9. }


Which of the below code can be insert at line 7 to make clean
compilation ?

A.    A a = new B(); Wrong Right

B.    A a = new B(5); Wrong Right

C.    A a = new A(String s); Wrong Right

D.    All of the above Wrong Right

Answer : A a = new B();

Explanation : A a = new B(); is correct because anonymous inner classes are no different from any
other class when it comes to polymorphism.

Learn more problems on : Variables and Loops

Discuss on this question

14.

Is this legal?
long longArr[];
int intArr[] = { 7 ,8 , 9};
longArr = intArr;

A.    yes Wrong Right

B.    no Wrong Right

C.    cannot be determined Wrong Right

D.    not applicable Wrong Right

Answer : no

Explanation : You cannot assign a reference to an array of primitives
to another unless they contain the same primitive types. 

Learn more problems on : Language Fundamentals

Discuss on this question

15.

What is the output for the below code ?

public class Tech {
public void tech() {
System.out.println("Tech");
}

}


public class Atech {

Tech a = new Tech() {
public void tech() {
System.out.println("anonymous tech");
}
};

public void dothis() {
a.tech();

}

public static void main(String... args){
Atech atech = new Atech();
atech.dothis();
}

A.    anonymous tech Wrong Right

B.    Compile Error  Wrong Right

C.    Tech Wrong Right

D.    anonymous tech Tech Wrong Right

Answer : anonymous tech

Explanation : This is anonymous subclass of the specified class type.
Anonymous inner class ( anonymous subclass ) overriden the Tech super class of tech() method.
Therefore Subclass method will get called.

Learn more problems on : Inner Classes

Discuss on this question

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