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.

Which of the following is correct (valid) declaration of a class?

Protected void acc();
}
"/> A.    public abstract class Car{
Protected void acc();
}
Wrong Right

Protected abstract void acc ( );
}
"/> B.    public interface class Car{
Protected abstract void acc ( );
}
Wrong Right

Protected abstract void acc ( );
}
"/> C.    public abstract class Car{
Protected abstract void acc ( );
}
Wrong Right

Protected abstract void acc (){
}
}
"/> D.    public abstract class Car{
Protected abstract void acc (){
}
}
Wrong Right

Answer : public abstract class Car{
Protected abstract void acc ( );
}

Explanation : In the first option a) method is not abstract so it should have implementation but in the example it is not there.

In the second option b) method is protected, actually interface methods are public abstract by default so it is not the Answer.

In the fourth one method is abstract but still it is implemented, so that is not the Answer.

So finally c) is the Answer.

Learn more problems on : Abstract

Discuss on this question

2.

What is the output for the below code?

import java.util.LinkedList;
import java.util.Queue;
public class Test {
public static void main(String... args) {
Queue q = new LinkedList();
q.add("newyork");
q.add("ca");
q.add("texas");
show(q);
}
public static void show(Queue q) {
q.add(new Integer(11));
while (!q.isEmpty ( ) )
System.out.print(q.poll() + " ");
}
}

A.    Compile error : Integer can't be added Wrong Right

B.    newyork ca texas 11 Wrong Right

C.    newyork ca texas Wrong Right

D.    None of the above Wrong Right

Answer : newyork ca texas 11

Explanation : q was originally declared as Queue, But in show( ) method it is passed as an
untyped Queue. Nothing in the compiler or JVM prevents us from adding an Integer after
that.
If the show method signature is public static void show(Queue q) than you
can't add Integer, Only String allowed. But public static void show(Queue q) is untyped
Queue so you can add Integer.
Y poll( ) Retrieves and removes the head of this queue, or returns null if this queue is
empty.

Learn more problems on : Collections

Discuss on this question

3.

 What will be the output of the program?
class Super{
public Integer getLength(){
return new Integer(4);
}
}

public class Sub extends Super{
public Long getLength(){
return new Long(5);
}

public static void main(String[] args){
Super sooper = new Super();
Sub sub = new Sub();
System.out.println(
sooper.getLength().toString() + "," + sub.getLength().toString() );
}
}

A.    4, 4 Wrong Right

B.    4, 5 Wrong Right

C.    5, 4 Wrong Right

D.    Compilation fails. Wrong Right

Answer : Compilation fails.

Explanation : Option D is correct, compilation fails - The return type of getLength ( ) in the super class is an object of reference type Integer and the return type in the sub class is an object of reference type Long.
In other words, it is not an override because of the change in the return type and it is also not an overload because the argument list has not changed.  

Learn more problems on : Declarations and Access Control

Discuss on this question

4.

You have a class file name Test.class inside javaproject directory.
Test.java source code is :
import java.util.Properties;
class Test {
public static void main (String[] args){
Properties p = System.getProperties();
System.out.println(p.getProperty("key1"));
}
}
you have issued below commands from command prompt.
cd javaproject
java -D key1=value1 Test
What is the output ?

A.    value1 Wrong Right

B.    null Wrong Right

C.    Run successfully but no output Wrong Right

D.    Run fails - java.lang.NoClassDefFoundError: key1=value1 Wrong Right

Answer : Run fails - java.lang.NoClassDefFoundError: key1=value1

Explanation : -D option , name=value pair must follow immediately, no spaces allowed. In this case
there is space between -D and key1=value1 So java.lang.NoClassDefFoundError:
key1=value1.

Learn more problems on : File

Discuss on this question

5.

class A{
Public static void main(String args[]){
String s1=Float.toString(5.55);
System.out.println(s1);
} }

A.    5.55 Wrong Right

B.    null Wrong Right

C.    compile time error Wrong Right

D.    runtime error Wrong Right

Answer : compile time error

Explanation : we can not convert float to String . if you try it will throw compile error.

Learn more problems on : Final and Datatypes

Discuss on this question

6.

class A{
Public static void main(String args[]){
int i=10;
test(i);test(10); test(20);
}
Public static void test(int i){
System.out.println(i);
}
}

A.    compile time error Wrong Right

B.    run time error Wrong Right

C.    10 10 20 Wrong Right

D.    no output Wrong Right

Answer : 10 10 20

Explanation : here the code which we have in main method will execute, and test() method we are calling three times from main by passing I value and two constant values like 10,20 so test() method will execute three times. To call test() method no need to create an object because test() method is declared as static ,so memory will be allocated automatically. You can call directly.

Learn more problems on : Flow Control

Discuss on this question

7.

public class X
{
public static void main(String [] args)
{
X x = new X();
X x2 = m1(x); /* Line 6 */
X x4 = new X();
x2 = x4; /* Line 8 */
doComplexStuff();
}
static X m1(X mx)
{
mx = new X();
return mx;
}
}


After line 8 runs. how many objects are eligible for garbage collection? 

A.    0 Wrong Right

B.    1 Wrong Right

C.    2 Wrong Right

D.    3 Wrong Right

Answer : 1

Explanation : By the time line 8 has run, the only object without a reference is the one generated as a result of line 6. Remember that "Java is pass by value," so the reference variable x is not affected by the m1() method.

Learn more problems on : Garbage Collections

Discuss on this question

8.

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


Class B extends A{
B(){
Super();
This(10);
System.out.println(2); }
B(int x){
System.out.println(2); }}
Class C extends B {
C(){
System.out.println(3);
Super();
} }

Class Manager{
Public static void main(String args[]){
B c=new B();
} }

A.    1,2 Wrong Right

B.    2,1 Wrong Right

C.    compile time error Wrong Right

D.    run time error Wrong Right

Answer : compile time error

Explanation : in a single constructor we can’t use both super() and this(), if you try to use then it will throw an compile time error.

Learn more problems on : Inheritance

Discuss on this question

9.

Interface A{
Int test();
}
Class Manager{
Public static void main(String args[]){
A a1=new A();
a1.test();
} }

A.    1 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 : We cannot create an object of an interface, if you try it will throw an error.

Learn more problems on : Interface

Discuss on this question

10.

Which statement is true for the class java.util.ArrayList?

A.    The elements in the collection are ordered. Wrong Right

B.    The collection is guaranteed to be immutable. Wrong Right

C.    The elements in the collection are guaranteed to be unique. Wrong Right

D.    The elements in the collection are accessed using a unique key. Wrong Right

Answer : The elements in the collection are ordered.

Explanation : Yes, always the elements in the collection are ordered.

Learn more problems on : Objects and Collections

Discuss on this question

11.

 Which two are equal?
1. 32/4
2. (8 >> 2) << 4
3. 2^5
4. 128 >>> 2
5. 2 >> 5

A.    1 and 2 Wrong Right

B.    2 and 4 Wrong Right

C.    1 and 3 Wrong Right

D.    2 and 3 Wrong Right

Answer : 2 and 4

Explanation : (2) and (4) are correct. (2) and (4) both evaluate to 32. (2) is shifting bits right then left using the signed bit shifters >> and <<. (4) is shifting bits using the unsigned operator >>>, but since the beginning number is positive the sign is maintained.
(1) evaluates to 8, (3) looks like 2 to the 5th power, but ^ is the Exclusive OR operator so (3) evaluates to 7. (5) evaluates to 0 (2 >> 5 is not 2 to the 5th).

Learn more problems on : Operators and Assignments

Discuss on this question

12.

What is the output for the below code ?


public class B {
public synchronized void printName(){
try{
System.out.println("printName");
Thread.sleep(5*1000);
}catch(InterruptedException e){
}
}
public synchronized void printValue(){
System.out.println("printValue");
}
}
public class Test extends Thread{
B b = new B();
public static void main(String argv[]) throws Exception{
Test t = new Test();
Thread t1 = new Thread(t,"t1");
Thread t2 = new Thread(t,"t2");
t1.start();
t2.start();
}
public void run(){
if(Thread.currentThread().getName().equals("t1")){
b.printName();
}else{
b.printValue();
}
}
}

A.    print : printName , then wait for 5 seconds then print : printValue Wrong Right

B.    print : printName then print : printValue Wrong Right

C.    print : printName then wait for 5 minutes then print : printValue Wrong Right

D.    Compilation succeed but Runtime Exception Wrong Right

Answer : print : printName , then wait for 5 seconds then print : printValue

Explanation : There is only one lock per object, if one thread has picked up the lock, no other thread can pick up the lock until the first thread releases the lock. printName() method acquire the lock for 5 seconds, So other threads cannot access the object. If one synchronized method of an instance is executing then other synchronized method of the same instance
should wait.

Learn more problems on : Threads

Discuss on this question

13.

What is the output for the below code ?


public class A {
int k;
boolean istrue;
static int p;
public void printValue() {
System.out.print(k);
System.out.print(istrue);
System.out.print(p);
}
}
public class Test{
public static void main(String argv[]){
A a = new A();
a.printValue();
}
}

A.    0 false 0 Wrong Right

B.    0 true 0 Wrong Right

C.    000 Wrong Right

D.    Compile error - static variable must be initialized before use. Wrong Right

Answer : 0 false 0

Explanation : Global and static variable need not be initialized before use. Default value of global and static int variable is zero. Default value of boolean variable is false. Remember local variable must be initialized before use.

Learn more problems on : Variables and Loops

Discuss on this question

14.

You have the following code in a file called Test.java

class Base{
public static void main(String[] args){
System.out.println("Hello");
}
}

public class Test extends Base{}

What will happen if you try to compile and run this?

A.    It will fail to compile. Wrong Right

B.    Runtime error Wrong Right

C.    Compiles and runs with no output. Wrong Right

D.    Compiles and runs printing "Hello" Wrong Right

Answer : Compiles and runs printing "Hello"

Explanation : This will compile and print "Hello"
The entry point for a standalone java program is
the main method of the class that is being run.
The java runtime system will look for that method
in class Test and find that it does have such a method.
It does not matter whether it is defined in the class itself
or is inherited from a parent class.   

Learn more problems on : Language Fundamentals

Discuss on this question

15.

Is the bellow code compile without error?
public class ThreadTest {
Runnable r = new Runnable() {
public void run() { }
};
}

A.    compile without error Wrong Right

B.    compile with error because Runnable is an Interface. Wrong Right

C.    Compilation succeed but Runtime Exception Wrong Right

D.    None of the above Wrong Right

Answer : compile without error

Explanation : instantiating an implementer of the Runnable interface (an anonymous
implementation class). So compile without error.

Learn more problems on : Inner Classes

Discuss on this question

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