Java Programming Test No : 8
Sign in to LucentBlackBoard
New Member to LucentBlackBoard?
Forgot Your Password?
Time left :
Java Programming Test No : 8
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.
Java Programming Test No : 8
Result and Statistics
Time Left :
Result and Statistics ( Java Programming Test No : 58 )
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 )
-
Feed back Form
Rate This Test :
Comments:
Menu Links
Answer : public class Employee extends Info implements Data {
Explanation : whenever you want to use interface then use implements keyword, and during abstract class use extends keyword. Vice versa is not true.
Learn more problems on : Abstract
2.
Which of the following statement is true about the assert statement. Select the one correct answer.
Answer : The program terminates on its first AssertionError.
Explanation : The option A is incorrect, as the Java compiler option is -source 1.4 . The option B is incorrect, as the runtime option is -ea or -enableassertions. If the logical expression evaluates to false, then the program generates an AssertionError, hence C is incorrect.
Learn more problems on : Assertions
3.
What is the output for the below code ?
Answer : true
Explanation : An array is always an instance of Object
Learn more problems on : Collections
4.
1. try{
2. // some code here
3.} catch (NullPointerException e1) {
4. System.out.print("a");
5.} catch (Exception e2) {
6. System.out.print("b");
7.} finally {
8. System.out.print("c");
9.}
If some sort of exception is thrown at line 2, which output is possible?
Answer : ac
Explanation : You can have any number of catch blocks, if exception is occurred from try, then it will check in immediate catch , if immediate catch block is able to handle then it will go inside that catch block. If not then it will go and check next available catch block. and finally will execute whether exception occurs or not. So answer is D).
Learn more problems on : Exceptions
5.
public class A {
public A() {
System.out.println("A");
}
}
public class B extends A implements Serializable {
public B() {
System.out.println("B");
}
}
public class Test {
public static void main(String... args) throws Exception {
B b = new B();
ObjectOutputStream save = new ObjectOutputStream(new FileOutputStream("datafile"));
save.writeObject(b);
save.flush();
ObjectInputStream restore = new ObjectInputStream(new FileInputStream("datafile"));
B z = (B) restore.readObject();
}
}
What is the output?
Answer : A B A
Explanation : On the time of deserialization , the Serializable object not create new object. So
constructor of class B does not called.
A is not Serializable object so constructor is called.
Learn more problems on : File
6.
Class F
{
Static void test(Byte I,Byte j){
System.out.println(“BByteâ€);
}
Static void test(byte …b){
System.out.println(“byteâ€);
}
Public static void main(String args[]){
byte s=10;
test(s,s);
}
}
Answer : byte
Explanation : Here test(s,s) will call test(byte…b) because these two are of type primitive.where as test(Byte , Byte) is of type class so it will not get called.
Learn more problems on : Final and Datatypes
7.
class F
{
Static public void main(String args[])
{
System.out.println(“HIâ€);
}
}
Answer : HI
Explanation : Here we have swaped static keyword and public access specifier, that doesn’t effect the execution but if you swap void and main it will throw an error. Normal execution , JVM will execute from main method and displays HI.
Learn more problems on : Flow Control
8.
void start() {
A a = new A();
B b = new B();
a.s(b);
b = null; /* Line 5 */
a = null; /* Line 6 */
System.out.println("start completed"); /* Line 7 */
}
Answer : There is no way to be absolutely certain.
Explanation : There is no explanation...
Learn more problems on : Garbage Collections
9.
interface moveable{
Void move();
Void stop();
}
Which is valid?
Answer : Public class bicycle implements moveable{
Public void move(){}
Public void stop(){}
}
Explanation : There is no explanation...
Learn more problems on : Interface
10.
class W{
Static void method(int I,int j ){
System.out.println(“intâ€); }
Static void method(byte…b){
System.out.println(“byteâ€); }
Public static void main(String args[]){
byte i=10;
method(i,i); }
}
Answer : int
Explanation : while calling method() from main() we are passing exactly two parameter as byte , as we are calling by passing only two so it will display int.
Learn more problems on : Objects and Collections
11.
class G{
Int I;
}
Class Manager{
Public static void main(String args[]){
System.out.println(G.i);
}
}
Answer : compile time error
Explanation : here variable I is non-static ,this variable can not be accessed from static function main(), if you try it will throw an compile time error.
Learn more problems on : Static Concept
12.
What is the output for the below code ?
Answer : waiting run 1225
Explanation : a.wait(); put thread on wait until not get notifed. A thread gets on this waiting list by
executing the wait() method of the target object. It doesn't execute any further
instructions until the notify() method of the target object is called. A thread to call wait() or notify(), the thread has to be the owner of the lock for that object.
Learn more problems on : Threads
13.
What is the output for the below code ?
1. public class Test {
2. public static void main(String[] args){
3. byte b = 6;
4. b+=8;
5. System.out.println(b);
6. b = b+7;
7. System.out.println(b);
8. }
9. }
Answer : Compilation fails with an error at line 6
Explanation : int or smaller expressions always resulting in an int. So compiler complain about Type mismatch: cannot convert from int to byte for b = b+7; But b += 7; // No problem because +=, -=, *=, and /= will all put in an implicit cast. b += 7 is same as b = (byte)b+7 so compiler not complain.
Learn more problems on : Variables and Loops
14.
What is the result that will be printed out ?
void aMethod()
{
float f = (1 / 4) * 10;
int i = Math.round(f);
System.out.println(i);
}
Answer : 0
Explanation : The result of 1/4 will be zero because integer
divion is carried out on the operands.
If you need to obtain a fractional value
you need to use either a float or double literal
as in 1F / 4F.
Learn more problems on : Language Fundamentals
15.
What is the output for the below code ?
class Outer {
static class Inner {
void go() {
System.out.println("Inner.go");
}
}
}
public class Test {
static class Inner1 {
void go() {
System.out.println("Inner1.go");
}
}
public static void main(String... args) throws Exception {
Outer.Inner bn = new Outer.Inner();
bn.go();
Inner1 in = new Inner1();
in.go();
}
}
Answer : Inner.go Inner1.go
Explanation : Static Inner class can be accessed without having an instance of the outer class. This is like other static members.
Learn more problems on : Inner Classes