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.

Public abstract class Wow {
Private int wow;
Public Wow (int wow) {
This.wow=wow;
}

Public void wow ( ) {}
Private void wowiz ( ) {}
}

A.    Compiles without any error Wrong Right

B.    It will not compile because abstract class cannot have private methods. Wrong Right

C.    It will not compile because abstract class cannot have instance variables. Wrong Right

D.    It will not compile because abstract class must have atleast one abstract method. Wrong Right

Answer : Compiles without any error

Explanation : There is no explanation...

Learn more problems on : Abstract

Discuss on this question

2.


public class Test {
public static void main(String[] args) {
int x = 0;
assert (x > 0): “assertion failed”;
System.out.println(“finished”);
 }
 }
What is the result?

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 : Compilation fails.

Explanation : This question is a bit tricky because it lacks the following information: It should include a
statement that says whether or not assertions are enabled. If they are indeed enabled, the
correction answer is C. but if they are not, the correct answer is A. Assertions are not enabled by default so if the question is not changed, the most logical answer is A.

Learn more problems on : Assertions

Discuss on this question

3.

What is the output for the below code?

import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
public class Test {
public static void main(String... args) {
Set s = new TreeSet();
s.add("7");
s.add(9);
Iterator itr = s.iterator();
while (itr.hasNext())
System.out.print(itr.next() + " ");
}
}

A.    Compile error Wrong Right

B.    Runtime Exception Wrong Right

C.    79 Wrong Right

D.    None of the above Wrong Right

Answer : Runtime Exception

Explanation : Without generics, the compiler does not know what type is appropriate for this
TreeSet, so it allows everything to compile. But at runtime the TreeSet will try to sort the
elements as they are added, and when it tries to compare an Integer with a String it will
throw a ClassCastException.

Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be
cast to java.lang.Integer.

Learn more problems on : Collections

Discuss on this question

4.

Which two statements are true for any concrete class implementing the java.lang.Runnable interface?
1. You can extend the Runnable interface as long as you override the public run ( ) method.
2. The class must contain a method called run ( ) from which all code for that thread will be initiated.
3. The class must contain an empty public void method named run ( ).
4. The class must contain a public void method named runnable ( ).
5. The class definition must include the words implements Threads and contain a method called run ( ).
6. The mandatory method must be public, with a return type of void, must be called run ( ), and cannot take any arguments.

A.    1 and 3 Wrong Right

B.    2 and 4 Wrong Right

C.    1 and 5 Wrong Right

D.    2 and 6 Wrong Right

Answer : 2 and 6

Explanation : (2) and (6). When a thread's run ( ) method completes, the thread will die. The run ( ) method must be declared public void and not take any arguments.
(1) is incorrect because classes can never extend interfaces. (3) is incorrect because the run ( ) method is typically not empty; if it were, the thread would do nothing. (4) is incorrect because the mandatory method is run ( ). (5) is incorrect because the class implements Runnable.

Learn more problems on : Declarations and Access Control

Discuss on this question

5.

What is the output for the below code ?
public class A {}
public class B implements Serializable {
private static A a = new A();
public static void main(String... args){
B b = new B();
try{
FileOutputStream fs = new
FileOutputStream("b.ser");
ObjectOutputStream os = new
ObjectOutputStream(fs);
os.writeObject(b);
os.close();
}catch(Exception e){
e.printStackTrace();
}
}
}

A.    Compilation Fail Wrong Right

B.    java.io.NotSerializableException: Because class A is not Serializable Wrong Right

C.    No Exception at Runtime Wrong Right

None of the above

"/> D.    

None of the above

Wrong Right

Answer : No Exception at Runtime

Explanation : No java.io.NotSerializableException, Because class A variable is static. static variables are not Serializable.

Learn more problems on : File

Discuss on this question

6.

Class Manager{
Public static void main(String args[]){
Double d=test(100);
System.out.println(“done”);
}
Static long test(float f){
return f; }
}

A.    100 Wrong Right

B.    done Wrong Right

C.    compile time error Wrong Right

D.    runtime error Wrong Right

Answer : compile time error

Explanation :
From main method() we are calling test() method by passing 100, but in a called function it is accepting of type float so it will throw compile time error.

Learn more problems on : Final and Datatypes

Discuss on this question

7.

Which statement is true?

A.    Calling Runtime.gc() will cause eligible objects to be garbage collected. Wrong Right

B.    The garbage collector uses a mark and sweep algorithm. Wrong Right

C.    If an object can be accessed from a live thread, it can't be garbage collected. Wrong Right

D.    If object 1 refers to object 2, then object 2 can't be garbage collected. Wrong Right

Answer : If an object can be accessed from a live thread, it can't be garbage collected.

Explanation : This is a great way to think about when objects can be garbage collected.
Option A and B assume guarantees that the garbage collector never makes.
Option D is wrong because of the now famous islands of isolation scenario.

Learn more problems on : Garbage Collections

Discuss on this question

8.

class A{
A(){
This(10);
System.out.println(1);
}
A(int i){
This();
System.out.println(2); }
}
Class Manager{
Public static void main(String args[]){
System.out.println(“done”);
} }

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 : here in class A there are two constructor one with no parameter, other with one parameter, in each constructor we are using this() keyword , from no parameter constructor we are calling parameter constructor using this() keyword, and from parameter constructor we are calling no parameter constructor using this() keyword, so it will become cyclic calling so it will throw an compile time error

Learn more problems on : Inheritance

Discuss on this question

9.

interface A{
Int i=0;
}
interface B extends A{
Int i=1;
}
interface C extends B{
Int i=2;
}

Class Manager implements C
{
Int i=3;
Public static void main(String args[])
{
C c1=(C)new Manager();
System.out.println(c1.i);
}
}

A.    3 Wrong Right

B.    ClassCastException Wrong Right

C.    compiletime error Wrong Right

D.    none of the above Wrong Right

Answer : 3

Explanation : Here a class Manager implements C which is an interface so it will not throw any compile time error,and while creating an object we are creating an object of manager and trying to store in an c1 variable which is of type C.and manager is also of type C.. So ans is a)

Learn more problems on : Interface

Discuss on this question

10.

Which of the following would compile without error?



A.     int a = Math.abs(-5);
Wrong Right

B.    int b = Math.abs(5.0);
Wrong Right

C.    int c = Math.abs(5.5F);
Wrong Right

D.    int d = Math.abs(5L); Wrong Right

Answer :  int a = Math.abs(-5);

Explanation : The return value of the Math.abs() method is always the same as the type of the parameter passed into that method.
In the case of A, an integer is passed in and so the result is also an integer which is fine for assignment to "int a".
The values used in B, C & D respectively are a double, a float and a long. The compiler will complain about a possible loss of precision if we try to assign the results to an "int".

Learn more problems on : java.lang.class

Discuss on this question

11.

What two statements are true about properly overridden hashCode() andequals() methods?


1. hashCode() doesn't have to be overridden if equals() is.
2. equals() doesn't have to be overridden if hashCode() is.
3. hashCode() can always return the same value, regardless of the object that invoked it.
4. equals() can be true even if it's comparing different objects.

A.    1 and 2 Wrong Right

B.    2 and 3 Wrong Right

C.    3 and 4 Wrong Right

D.    1 and 3 Wrong Right

Answer : 3 and 4

Explanation : (3) and (4) are correct.
(1) and (2) are incorrect because by contract hashCode() and equals() can't be overridden unless both are overridden.

Learn more problems on : Objects and Collections

Discuss on this question

12.

import java.awt.Button;
class CompareReference
{
public static void main(String [] args)
{
float f = 42.0f;
float [] f1 = new float[2];
float [] f2 = new float[2];
float [] f3 = f1;
long x = 42;
f1[0] = 42.0f;
}
}
which three statements are true?


1. f1 == f2
2. f1 == f3
3. f2 == f1[1]
4. x == f1[0]
5. f == f1[0]

A.    1, 2 and 3 Wrong Right

B.    2, 4 and 5 Wrong Right

C.    3, 4 and 5 Wrong Right

D.    1, 4 and 5 Wrong Right

Answer : 2, 4 and 5

Explanation : (2) is correct because the reference variables f1 and f3 refer to the same array object.
(4) is correct because it is legal to compare integer and floating-point types.
(5) is correct because it is legal to compare a variable with an array element.
(3) is incorrect because f2 is an array object and f1[1] is an array element.

Learn more problems on : Operators and Assignments

Discuss on this question

13.

What is the output for the below code ?


class A implements Runnable{
public void run(){
try{
for(int i=0;i<4;i++){
Thread.sleep(100);
System.out.println(Thread.currentThread().getName());
}
}catch(InterruptedException e){
}
}
}
public class Test {
public static void main(String argv[]) throws Exception{
A a = new A();
Thread t = new Thread(a,"A");
Thread t1 = new Thread(a,"B");
t.start();
t.join();
t1.start();
}
}

A.    A A A A B B B B Wrong Right

B.    A B A B A B A B Wrong Right

C.    Output order is not guaranteed Wrong Right

D.    Compilation succeed but Runtime Exception Wrong Right

Answer : A A A A B B B B

Explanation : t.join(); means Threat t must finish before Thread t1 start.

Learn more problems on : Threads

Discuss on this question

14.

What is the output for the below code ?


1. public class Test {
2. public static void main(String[] args){
3. int i = 010;
4. int j = 07;
5. System.out.println(i);
6. System.out.println(j);
7. }
8. }

A.    8 7 Wrong Right

B.    10 7 Wrong Right

C.    Compilation fails with an error at line 3 Wrong Right

D.    Compilation fails with an error at line 5 Wrong Right

Answer : 8 7

Explanation : By placing a zero in front of the number is an integer in octal form. 010 is in octal form so its value is 8.

Learn more problems on : Variables and Loops

Discuss on this question

15.

What will be the output of the program?

public abstract class AbstractTest
{
public int getNum()
{
return 45;
}
public abstract class Bar
{
public int getNum()
{
return 38;
}
}
public static void main (String [] args)
{
AbstractTest t = new AbstractTest()
{
public int getNum()
{
return 22;
}
};
AbstractTest.Bar f = t.new Bar()
{
public int getNum()
{
return 57;
}
};

System.out.println(f.getNum() + " " + t.getNum());
}
}

A.    57 22 Wrong Right

B.    45 38 Wrong Right

C.    45 57 Wrong Right

D.    An exception occurs at runtime. Wrong Right

Answer : 57 22

Explanation : You can define an inner class as abstract, which means you can instantiate only concrete subclasses of the abstract inner class. The object referenced by the variable t is an instance of an anonymous subclass of AbstractTest, and the anonymous class overrides the getNum() method to return 22. The variable referenced by f is an instance of an anonymous subclass of Bar, and the anonymous Bar subclass also overrides the getNum() method (to return 57). Remember that to instantiate a Bar instance, we need an instance of the enclosingAbstractTest class to tie to the new Bar inner class instance. AbstractTestcan't be instantiated because it's abstract, so we created an anonymous subclass (non-abstract) and then used the instance of that anonymous subclass to tie to the new Bar subclass instance.

Learn more problems on : Inner Classes

Discuss on this question

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