Cookies Consent

This website uses cookies to ensure you get the best experience on our website.

Learn More

Java (Basic) Certification MCQs | HackerRank

9 min read
  1. What is the output of following program?
sourcecode
public class BitPuzzel { public static void main(String[] args) { int mask = 0x000F; int value = 0x2222; System.out.println(value & mask); } }
sourcecode
Answer: 2
  1. What is the output of following program?
sourcecode
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)); } }
sourcecode
Answer: Compilation Fails due to error at line 9, non-static method referenced from a static context
  1. Which is the right answer to the following?
sourcecode
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) { ; } }
sourcecode
Answer: Compilation fails due to an error on line 6
  1. Find the Output
sourcecode
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 */ }
sourcecode
Answer: 9.0
  1. What is a covariant return type?
sourcecode
Answer: The overiding method can have base type as the return type instead of the derived type
Labels : #hackerrank certification ,#java (basic) ,

Post a Comment