a) compile error at line 5.
b) 0 to 49 printed continuously.
c) runtime error.
d) null printed 50 times.
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is d) null printed 50 times. String array is assigned null by default.
Correct! null printed 50 times. String array is assigned null by default.
3. For the code below :
class StringCheck {
public static void main(String[] args) {
String str = null;
System.out.print(str);
}
}
a) Cannot access str without initialising.
b) NullPointerException thrown.
c) null is printed as output.
d) prints blank space
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is c) null is printed as output.
Correct! null is printed as output.
4. For the code below :
public class Test {
public void doIt() {
if(this == null)
System.out.println("this is null");
else
System.out.println("this is not null");
}
public static void main (String [] args) {
Test t = new Test();
t.doIt();
}
}
a) Compile error : this can never be null
b) Gives output: this is null
c) Gives output: this is not null
d) Runtime exception
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is c) Gives output: this is not null
Correct! Gives output: this is not null
5. Java implements polymorphism by :
1. keyword extends
2. function overriding
3. function overloading
4. keyword implements
a) 1 and 4
b) 2 and 3
c) None of them
d) All of them
Wrong! Try again..
Wrong Again! Try one more chance.
Wrong! The correct answer is b) overriding and overloading ensures multiple behaviour, thus implementing polymorphism
Correct! overriding and overloading ensures multiple behaviour, thus implementing polymorphism
6. What is the output for the foll :
public class Test {
public static void main(String [] args) {
short a, b, c=0;
a=1;
b=2;
c=a+b;
System.out.println(c);
}
}
a) Compile error.
b) 3
c) 3.0
d) Runtime exception
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is a) Compile error. In the expression c=a+b, a and b are converted to int. Casting can solve the issue: c=(short)(a+b);
Correct!
In the expression c=a+b, a and b are converted to int. Casting can solve the issue: c=(short)(a+b);
7. What is the output :
import java.io.IOException;
public class Test {
public Test () {
try {
m1();
System.out.println("No error");
}
catch (IOException e) {
System.out.println("IOException caught");
}
catch (Exception e) {
System.out.println("Exception caught");
}
}
public void m1() {
throw new IOException();
}
public static void main (String [] args) {
Test t = new Test();
}
}
a) Compile error
b) IOException caught
c) Exception caught
d) No error
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is a) Compile error. IOException must be declared to be thrown in m1()
Correct! IOException must be declared to be thrown in m1()