1. For the below:
public class Datatype extends DatatypeParent{
public static void go(Short n){
System.out.println("Short " + n);
}
public static void go(int n){
System.out.println("int " + n);
}
public static void main(String [] args){
short y = 6;
go(y);
}
}
public class DatatypeParent {
public static void go(short n){
System.out.println("P short " + n);
}
}
a) Gives output: P short 6 b) Gives output: Short 6 c) Compile error d) Gives output: int 6
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is a) Gives output: P short 6
Correct! Gives output: P short 6
2. wait() is a method of :
a) Thread b) Class c) Object d) Runnable
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is c) Object
Correct! Object
3. What is the output?
public class MyWrapper {
public static void main( String args[] ) {
Integer no1 = 300, no2 = 300;
System.out.print((no1==no2) + ", ");
Integer no3 = 127, no4 = 127;
System.out.print(no3==no4);
}
}
a) true, true b) false, false c) false, true d) compile error
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is c)false, true Value upto 127 is primitive int
Correct! Value upto 127 is primitive int
4. What is the output if run as : java A B
public class A {
public static void main(String[] args) {
System.out.print("A ");
}
}
public class B {
public static void main(String[] args) {
System.out.print("B ");
}
}
a) A, B b) B, A c) Run time error d) A
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is d) A. B is args[0] for main() of A
Correct! A. B is args[0] for main() of A
5. In the class File, the method createNewFile()
A. creates a new file if it does not exist
B. overwrites existing file
C. does not overwrite existing file
D. throws IOException if file exists
a) C and D b) A and D c) A and B d) A and C
Wrong! Try again..
Wrong Again! Try one more chance.
Wrong! The correct answer is d) A and C
Correct! A and C
6. What is the output?
public class Test {
public float check(float a, float b){
return a + b + 1;
}
public double check(double a, double b){
return a + b + 2;
}
public int check(int a, int b){
return a + b;
}
public static void main(String args[]) {
Test tst = new Test();
System.out.println( Math.round(tst.check(10,20)) +" " +
Math.round(tst.check(10,20f))+" " +
Math.round(tst.check(10,20.02)) );
}
a) 30 31 32 b) 31 31 32 c) 30 30 32 d) Compile Error
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is a)30 31 32
Correct! 30 31 32
7. The correct way to create a custom annotation @CanRun is :
a) public @class CanRun b) public interface @CanRun c) public @interface CanRun d) public @annotation CanRun
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is c) public @interface CanRun