- What is the output of following program?
public class BitPuzzel {
public static void main(String[] args) {
int mask = 0x000F;
int value = 0x2222;
System.out.println(value & mask);
}
}
: 2 Answer
- What is the output of following program?
public class A {
int add(int i, int j) {
return i + j;
}
}
public class B extends A {
public static void main(String[] args) {
short s = 9;
System.out.println(add(s, 6));
}
}
: Compilation Fails due to error at line 9, non-static method referenced from a static context Answer
- Which is the right answer to the following?
public interface Syrupable {
void getSugary();
}
abstract class Pancake implements Syrupable {}
class BuleBerryPancake implements Pancake {
public void getSugary() { ; }
}
class SourdoughBuleBerryPancake extends BuleBerryPancake {
void getSugary(int s) { ; }
}
: Compilation fails due to an error on line 6 Answer
- Find the Output
try {
Float f = new Float("3.0");
int x = f.intValue();
System.out.println("x : "+x);
byte b = f.byteValue();
System.out.println("b : "+b);
double d = f.doubleValue();
System.out.println("d : "+d);
System.out.println(x + b + d);
}
catch (NumberFormatException e) /* Line 9 */
{
System.out.println("bad number"); /* Line 11 */
}
: 9.0 Answer
- What is a covariant return type?
: The overiding method can have base type as the return type instead of the derived type Answer