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


Can we declare constructor as abstract?

A.    Yes Wrong Right

B.    No Wrong Right

C.    Cannot be determined Wrong Right

D.    None of the above Wrong Right

Answer : No

Explanation : Abstract methods will not have implementation. If you want to implement then you should do it through the child class. Here in the example, constructor Foo( ) is declared as abstract.

Actually constructors are not inherited to child class, constructor are specific to class if you try to make constructor as abstract then it will throw an compile time error.

Learn more problems on : Abstract

Discuss on this question

2.

Which of the following statements is true?

A.    Assertions can be enabled or disabled on a class-by-class basis. Wrong Right

B.    Conditional compilation is used to allow tested classes to run at full speed. Wrong Right

C.    Assertions are appropriate for checking the validity of arguments in a method. Wrong Right

D.    The programmer can choose to execute a return statement or to throw an exception if an assertion fails. Wrong Right

Answer : Assertions can be enabled or disabled on a class-by-class basis.

Explanation : Option A is correct. The assertion status can be set for a named top-level class and any nested classes contained therein. This setting takes precedence over the class loader's default assertion status, and over any applicable per-package default. If the named class is not a top-level class, the change of status will have no effect on the actual assertion status of any class.
Option B is wrong. Is there such a thing as conditional compilation in Java?
Option C is wrong. For private methods - yes. But do not use assertions to check the parameters of a public method. An assert is inappropriate in public methods because the method guarantees that it will always enforce the argument checks. A public method must check its arguments whether or not assertions are enabled. Further, the assert construct does not throw an exception of the specified type. It can throw only an AssertionError.
Option D is wrong. Because you're never supposed to handle an assertion failure. That means don't catch it with a catch clause and attempt to recover.

Learn more problems on : Assertions

Discuss on this question

3.

interface Base{
boolean m1 ( );
byte m2(short s);
}

Which of the two code fragments will compile?
1. interface Base2 implements Base {}
2. abstract class Class2 extends Base
{ public boolean m1(){ return true; }}
3. abstract class Class2 implements Base {}
4. abstract class Class2 implements Base
{ public boolean m1(){ return (7 > 4); }}
5. abstract class Class2 implements Base
{ protected boolean m1(){ return (5 > 7) }} 

A.    1 and 2 Wrong Right

B.    2 and 3 Wrong Right

C.    3 and 4 Wrong Right

D.    3 and 4 Wrong Right

Answer : 3 and 4

Explanation : (3) is correct because an abstract class doesn't have to implement any or all of its interface's methods. (4) is correct because the method is correctly implemented ((7 > 4) is a boolean).
(1) is incorrect because interfaces don't implement anything. (2) is incorrect because classes don't extend interfaces. (5) is incorrect because interface methods are implicitly public, so the methods being implemented must be public.

Learn more problems on : Declarations and Access Control

Discuss on this question

4.

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

 }
}
Output?

A.    one    Wrong Right

B.    runtime error Wrong Right

C.    compile time error Wrong Right

D.    none of the above Wrong Right

Answer : compile time error

Explanation : If you write a try block there should be a catch block or finally block, if there is no catch or finally it will throw compile time error.

Learn more problems on : Exceptions

Discuss on this question

5.

Public class Manager{
Static final String name=”init”;
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 value is fixed. Here while declare a variable they have initialized , and inside a static variable also they have initialized. Therefore two times they can’t initialize a same final variable if so it will throw an compile time error.

Learn more problems on : Final and Datatypes

Discuss on this question

6.

What will be the output of the program?


for(int i = 0; i < 3; i++)
{
switch(i)
{
case 0: break;
case 1: System.out.print("one ");
case 2: System.out.print("two ");
case 3: System.out.print("three ");
}
}
System.out.println("done");

A.    done Wrong Right

B.    one two done Wrong Right

C.    one two three done Wrong Right

D.    one two three two three done Wrong Right

Answer : one two three two three done

Explanation : The variable i will have the values 0, 1 and 2.
When i is 0, nothing will be printed because of the break in case 0.
When i is 1, "one two three" will be output because case 1, case 2 and case 3will be executed (they don't have break statements).
When i is 2, "two three" will be output because case 2 and case 3 will be executed (again no break statements).
Finally, when the for loop finishes "done" will be output.

Learn more problems on : Flow Control

Discuss on this question

7.

class A{
A(int i){
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[]){
A a=new A(10);
B b1=new B(20);
} }

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 : compile time error

Explanation : in main() method we are creating an object of class A as well as class B by calling A and B class constructor, class B constructor will call super class constructor because in each constructor body super() keyword will be there by default with no parameter ,but in class A there is no constructor with no parameter ,so it will throw an compile time error.

Learn more problems on : Inheritance

Discuss on this question

8.

interface A {
Void test();
}
Public class Manager implements A{
Public void test(){
System.out.println(“manager”);
}
Public static void main(String args[])
{
Manager m=new Manager();
m.test();
}
}

A.    manager Wrong Right

B.    no output Wrong Right

C.    compile time error Wrong Right

D.    runtime error Wrong Right

Answer : manager

Explanation : An interface can extend another interface but a class can only implement an interface, so here class Manager implements A, so ans is a)

Learn more problems on : Interface

Discuss on this question

9.

What will be the output of the program?


String x = "xyz";
x.toUpperCase(); /* Line 2 */
String y = x.replace('Y', 'y');
y = y + "abc";
System.out.println(y);

A.    abcXyZ Wrong Right

B.    abcxyz Wrong Right

C.    xyzabc Wrong Right

D.    XyZabc Wrong Right

Answer : xyzabc

Explanation : Line 2 creates a new String object with the value "XYZ", but this new object is immediately lost because there is no reference to it. Line 3 creates a new Stringobject referenced by y. This new String object has the value "xyz" because there was no "Y" in the String object referred to by x. Line 4 creates a new Stringobject, appends "abc" to the value "xyz", and refers y to the result.

Learn more problems on : java.lang.class

Discuss on this question

10.

Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object?

A.    java.lang.String Wrong Right

B.    java.lang.Double Wrong Right

C.    java.lang.StringBuffer Wrong Right

D.    java.lang.Character Wrong Right

Answer : java.lang.StringBuffer

Explanation : java.lang.StringBuffer is the only class in the list that uses the default methods provided by class Object. 

Learn more problems on : Objects and Collections

Discuss on this question

11.

What will be the output of the program?
class Test
{
public static void main(String [] args)
{
int x= 0;
int y= 0;
for (int z = 0; z < 5; z++)
{
if (( ++x > 2 ) || (++y > 2))
{
x++;
}
}
System.out.println(x + " " + y);
}
}

A.    5 3 Wrong Right

B.    8 2 Wrong Right

C.    8 3 Wrong Right

D.    8 5 Wrong Right

Answer : 8 2

Explanation : The first two iterations of the for loop both x and y are incremented. On the third iteration x is incremented, and for the first time becomes greater than 2. The short circuit or operator || keeps y from ever being incremented again and x is incremented twice on each of the last three iterations.

Learn more problems on : Operators and Assignments

Discuss on this question

12.

class J{
Static int I;
Static
{
System.out.println(i);
I=100;
}
Public static void main(String args[])
{
System.out.println(i);
}
Static
{
System.out.println(i);
I=200;
}

}

A.    0 200 100 Wrong Right

B.    0 100 200 Wrong Right

C.    compile time error Wrong Right

D.    200 100 0 Wrong Right

Answer : 0 100 200

Explanation : here we have declared two SIB(static initialization block), JVM always executes SIB first before the main() method , then it executes main() method,if you have more than one SIB then JVM will execute in the order in which they appear the program , and if you declare a global variable and don’t initialize it then it will take default value depending on the datatype. So in first SIB default value of I will be displayed , and I will be initialized to 100, and in second SIB 100 will displayed and initialized to 200 then in main() 200 will be displayed. So ans b) is correct.

Learn more problems on : Static Concept

Discuss on this question

13.

What is the output for the below code ?

public class Test {
public static void main(String... args) {
int a =5 , b=6, c =7;
System.out.println("Value is "+ b +c);
System.out.println(a + b +c);
System.out.println("String "+(b+c));
}
}

A.    Value is 67 18 String 13 Wrong Right

B.    Value is 13 18 String 13 Wrong Right

C.    Value is 13 18 String Wrong Right

D.    Compilation fails Wrong Right

Answer : Compilation fails

Explanation : If the left hand operand is not a String then + operator treat as plus BUT if left hand
operand is a String then + perform String concatenation.

Learn more problems on : Variables and Loops

Discuss on this question

14.

True or False.
The range of a byte is from -127 to 128

A.    True Wrong Right

B.    False Wrong Right

C.    Cannot be determined Wrong Right

D.    Error Wrong Right

Answer : False

Explanation : The statement is false. The range of an array
is from - 128 to 127 

Learn more problems on : Language Fundamentals

Discuss on this question

15.

What is the output for the below code ?

public class Outer {
private int a = 7;

class Inner {
public void displayValue() {
System.out.println("Value of a is " + a);
}
}
}


public class Test {

public static void main(String... args) throws Exception {
Outer mo = new Outer();
Outer.Inner inner = mo.new Inner();
inner.displayValue();

}

}


A.    Value of a is 7 Wrong Right

B.    Compile Error - not able to access private member. Wrong Right

C.    Runtime Exception Wrong Right

D.    Value of a is 8 Wrong Right

Answer : Value of a is 7

Explanation : An inner class instance can never stand alone without a direct relationship to an instance of the outer class.
you can access the inner class is through a live instance of the outer class.
Inner class can access private member of the outer class.

Learn more problems on : Inner Classes

Discuss on this question

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