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 {
Public static void main (String args[]){
System.out.println (“Foo”);
}

}

A.    compile time error Wrong Right

B.    runtime error Wrong Right

C.    foo Wrong Right

D.    none of the above Wrong Right

Answer : foo

Explanation : Here Foo is a abstract class. An abstract class can contain non-abstract method.

In the example, main ( ) method is a non-abstract method so it will not throw any error. It will display Foo.

Learn more problems on : Abstract

Discuss on this question

2.

 public class Test2{
public static int x;
public static int foo(int y) {
return y * 2;
}
public static void main(String [] args) {
int z = 5;
assert z > 0; /* Line 9 */
assert z > 2: foo(z); /* Line 10 */
if ( z < 7 )
assert z > 4; /* Line 12 */
switch (z) {
case 4: System.out.println("4");
case 5: System.out.println("5");
default: assert z < 10;
}
if ( z < 10 )
assert z > 4: z++; /* Line 20 */
System.out.println(z);
}
}

Which line is an example of inappropriate use of assertions? 

A.    Line 9 Wrong Right

B.    Line 10 Wrong Right

C.    Line 12 Wrong Right

D.    Line 20 Wrong Right

Answer : Line 20

Explanation : Assert statements should not cause side effects. Line 20 changes the value of z if the assert statement is false.
Option A is fine; a second expression in an assert statement is not required.
Option B is fine because it is perfectly acceptable to call a method with the second expression of an assert statement.
Option C is fine because it is proper to call an assert statement conditionally.

Learn more problems on : Assertions

Discuss on this question

3.

What is the output of below code?

public class Bean{
private String str;
Bean(String str ){
this.str = str;
}
public String getStr() {
return str;
}
public boolean equals(Object o){
if (!(o instanceof Bean)) {
return false;
}
return ((Bean) o).getStr().equals(str);
}


public int hashCode() {
return 12345;
}
public String toString() {
return str;
}
}

import java.util.HashSet;
public class Test {
public static void main(String ... sss) {
HashSet myMap = new HashSet();
String s1 = new String("das");
String s2 = new String("das");
Bean s3 = new Bean("abcdef");
Bean s4 = new Bean("abcdef");
myMap.add(s1);
myMap.add(s2);
myMap.add(s3);
myMap.add(s4);
System.out.println(myMap);
}
}

A.    das abcdef Wrong Right

B.    das abcdef das abcdef Wrong Right

C.    das das abcdef abcdef Wrong Right

D.    das Wrong Right

Answer : das abcdef

Explanation : Implement 'equals' and 'hashCode' methods to get unique result in Set.

Learn more problems on : Collections

Discuss on this question

4.

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

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

A.    one , two , three Wrong Right

B.    one Wrong Right

C.    one , three Wrong Right

D.    compile time error Wrong Right

Answer : one , three

Explanation : In the above example only try and finally will execute, as there is no exception catch block will not execute.
So c) is correct.

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();
}
}

What is the output?

A.    A A Wrong Right

B.    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.

 Public class Manager{
Static final String name;
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.    runtime error Wrong Right

Answer : compile time error

Explanation : final variable should be initialized , here without initializing they are trying to access the value of name variable so it will throw compile time error.

Learn more problems on : Final and Datatypes

Discuss on this question

7.

What will be the output of the program?


int I = 0;
outer:
while (true)
{
I++;
inner:
for (int j = 0; j < 10; j++)
{
I += j;
if (j == 3)
continue inner;
break outer;
}
continue outer;
}
System.out.println(I);

A.    1 Wrong Right

B.    2 Wrong Right

C.    3 Wrong Right

D.    4 Wrong Right

Answer : 1

Explanation : The program flows as follows: I will be incremented after the while loop is entered, then I will be incremented (by zero) when the for loop is entered. The if statement evaluates to false, and the continue statement is never reached. The break statement tells the JVM to break out of the outer loop, at which point I is printed and the fragment is done.

Learn more problems on : Flow Control

Discuss on this question

8.

What is the output for the below code ?


public class A {
public void printValue(){
System.out.println("A");
}
}
public class B extends A {
public void printValue(){
System.out.println("B");
}
}
1. public class Test {
2. public static void main(String... args) {
3. A b = new B();
4. newValue(b);
5. }
6. public static void newValue(A a){
7. if(a instanceof B){
8. ((B)a).printValue();
9. }
10. }
11. }

A.    A Wrong Right

B.    B Wrong Right

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

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

Answer : B

Explanation : instanceof operator is used for object reference variables to check whether an object is of a particular type. In newValue(b); b is instance of B So works properly.

Learn more problems on : Inheritance

Discuss on this question

9.

which two are true?

A.    An interface can implement another interface.

a class can implement more than one interface.
Wrong Right

B.    a class can implement more than one interface.

every class can implement at least one interface. Wrong Right

C.    An interface can implement another interface.

every class can implement at least one interface.

Wrong Right

D.    a class can implement more than one interface.

many class can implement same interface.
Wrong Right

Answer : a class can implement more than one interface.

many class can implement same interface.

Explanation : There is no explanation...

Learn more problems on : Interface

Discuss on this question

10.

What will be the output of the program?


public class WrapTest
{
public static void main(String [] args)
{
int result = 0;
short s = 42;
Long x = new Long("42");
Long y = new Long(42);
Short z = new Short("42");
Short x2 = new Short(s);
Integer y2 = new Integer("42");
Integer z2 = new Integer(42);

if (x == y) /* Line 13 */
result = 1;
if (x.equals(y) ) /* Line 15 */
result = result + 10;
if (x.equals(z) ) /* Line 17 */
result = result + 100;
if (x.equals(x2) ) /* Line 19 */
result = result + 1000;
if (x.equals(z2) ) /* Line 21 */
result = result + 10000;

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

A.    result = 1 Wrong Right

B.    result = 10 Wrong Right

C.    result = 11 Wrong Right

D.    result = 11010 Wrong Right

Answer : result = 10

Explanation : Line 13 fails because == compares reference values, not object values. Line 15 succeeds because both String and primitive wrapper constructors resolve to the same value (except for the Character wrapper). Lines 17, 19, and 21 fail because the equals() method fails if the object classes being compared are different and not in the same tree hierarchy.

Learn more problems on : java.lang.class

Discuss on this question

11.

1. What will be the output of the program? 


class PassA
{
public static void main(String [] args)
{
PassA p = new PassA();
p.start();
}

void start()
{
long [] a1 = {3,4,5};
long [] a2 = fix(a1);
System.out.print(a1[0] + a1[1] + a1[2] + " ");
System.out.println(a2[0] + a2[1] + a2[2]);
}

long [] fix(long [] a3)
{
a3[1] = 7;
return a3;
}
}

A.    12 15 Wrong Right

B.    15 15 Wrong Right

C.    345375 Wrong Right

D.    375375 Wrong Right

Answer : 15 15

Explanation : The reference variables a1 and a3 refer to the same long array object. When the [1] element is updated in the fix() method, it is updating the array referred to by a1. The reference variable a2 refers to the same array object.
So Output: 3+7+5+" "3+7+5
Output: 15 15 Because Numeric values will be added 

Learn more problems on : Operators and Assignments

Discuss on this question

12.

class A{

Static int i=10;
Static int j=I;
Public static void main(String args[]){
System.out.println(i);
System.out.println(j);
}
}

A.    compile time error Wrong Right

B.    run time error

Wrong Right

C.    10 10 Wrong Right

D.    no output Wrong Right

Answer : 10 10

Explanation : Here I and j are static global variable ,these static variables are accessed inside a main() method, as these are static variable no need to create an object we can access directly because for static variables memory will be allocated automatically. So the value of I and j will displayed inside main() method.

Learn more problems on : Static Concept

Discuss on this question

13.

What is the output for the below code ?
1. public class A {
2. int add(int i, int j){
3. return i+j;
4. }
5.}
6.public class B extends A{
7. public static void main(String argv[]){
8. short s = 9;
9. System.out.println(add(s,6));
10. }
11.}

A.    Compile fail due to error on line no 2 Wrong Right

B.    Compile fail due to error on line no 9 Wrong Right

C.    Compile fail due to error on line no 8 Wrong Right

D.    15 Wrong Right

Answer : Compile fail due to error on line no 9

Explanation : Cannot make a static reference to the non-static method add(int, int) from the type A. The short s is autoboxed correctly, but the add() method cannot be invoked from a static method because add() method is not static.

Learn more problems on : Variables and Loops

Discuss on this question

14.

What will happen if you try to compile and run this ?
public class Test{
static{
print(10);
}
static void print(int x){
System.out.println(x);
System.exit(0);
}
}

A.    Compiler error. Wrong Right

B.    Will throw a NoSuchMethod error at runtime. Wrong Right

C.    It will compile and run printing out "10" Wrong Right

D.     It will run with no output. Wrong Right

E.    It will run and print "10" and then crash with an error.       Wrong Right

Answer : It will compile and run printing out "10"

Explanation : This will run, print a message and terminate gracefully.
The runtime system needs to load the class before it can look
for the main method. So the static initializer will run first
and print "10". Immediately after that System.exit(0) will be called
terminating the program before an error can be thrown. 

Learn more problems on : Language Fundamentals

Discuss on this question

15.

 What will be the output of the program?
public class HorseTest
{
public static void main (String [] args)
{
class Horse
{
public String name; /* Line 7 */
public Horse(String s)
{
name = s;
}
} /* class Horse ends */

Object obj = new Horse("Zippo"); /* Line 13 */
Horse h = (Horse) obj; /* Line 14 */
System.out.println(h.name);
}
} /* class HorseTest ends */

A.    An exception occurs at runtime at line 10. Wrong Right

B.    It prints "Zippo". Wrong Right

C.    Compilation fails because of an error on line 7. Wrong Right

D.    Compilation fails because of an error on line 13. Wrong Right

Answer : It prints "Zippo".

Explanation : The code in the HorseTest class is perfectly legal. Line 13 creates an instance of the method-local inner class Horse, using a reference variable declared as type Object. Line 14 casts the Horse object to a Horse reference variable, which allows line 15 to compile. If line 14 were removed, the HorseTest code would not compile, because class Object does not have a name variable.

Learn more problems on : Inner Classes

Discuss on this question

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