1. Which of the following are NOT true?
1. C++ is Object Oriented
2. Java is OS independent
3. C is used in embedded systems
4. Java is not used as stand alone application
5. Java can be compiled to get an OS executable file
a) 4 and 5 b) 3 and 4
c) 3 and 5 d) None of the above
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is a) 4 and 5 .
Correct! 4 and 5 are NOT true
2. What is the output?
String s1 = new String("Happy");
String s2 = new String("Happy");
String s3 = "Happy";
String s4 = "Happy" ;
System.out.print( "s1==s2 :"+(s1==s2));
System.out.print( ", s3==s4 :"+(s3==s4));
a) s1==s2 :true, s3==s4 :true
b) s1==s2 :false, s3==s4 :true c) s1==s2 :true, s3==s4 :false d) s1==s2 :false, s3==s4 :false
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is b)s1==s2 :false, s3==s4 :true. s3 and s4 belong to String pool and share the same object
Correct! s3 and s4 belong to String pool and share the same object.
3. What is the output ?
public static void main(String[] args) {
String str = "Smart";
updateMe(str);
System.out.println(str);
}
public static void updateMe(String str) {
str = str.concat(" guy");
}
a) Compile Error b) Smart guy c) Smart d) guy
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is c) Smart. String is immutable.
Correct! String is immutable
4. What is the output?
String[][] names = {
{"Mr.", "Mrs.", "Ms."},
{"John", "Gupta", "Hegde", "Khan"},
{":M", ":F"}
};
System.out.println(names[0][2] + names[1][2]+ names[2][1]);
a) Compile error b) Mrs.Gupta : M c) Ms.Hegde : F d) Mr.Khan : M
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is c) Ms.Hegde : F. (A two dimensional array is an array of arrays)
Correct! A two dimensional array is an array of arrays
5. What is the output?
public class Test{
private final int BASIC;
public Test() {
BASIC = 15000;
}
public void show() {
System.out.println("basic="+BASIC);
}
public static void main(String args[]) {
Test test = new Test();
test.show();
}
}
a) Compile error b) basic=15000 c) basic=0 d) basic=null
Wrong! Try again..
Wrong Again! Try one more chance.
Wrong! The correct answer is b) basic=15000. final variable can be initialised in the constructor
Correct! final variable can be initialised in the constructor
6. Following program:
public class Test {
public void printMe() {
try{
System.out.println("before");
wait(2000);
System.out.println("after");
}
catch(InterruptedException e){}
}
public static void main(String[] args) {
Test t = new Test();
t.printMe();
}
}
a) Throws Exception during run time b) Error during compilation c) Gives output: before and after 2 seconds : after d) None of above
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is a) wait() should be used in synchronized block
Correct! wait() should be used in synchronized block
7. For following method :
public void check(boolean a, boolean b) {
if( a ) {
System.out.println( "A" );
} else if ( a && b ) {
System.out.println( "A&&B" );
} else {
if ( !b ) {
System.out.println( "notB" );
} else {
System.out.println( "ELSE" );
}
}
}
a) if a=true, and b=true output is A&&B b) if a=true, and b=false output is notB c) if a=false, and b=true output is ELSE d) if a=false, and b=false output is ELSE
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is c) if a=false, and b=true output is ELSE