Submitted Questions

  • Given the two methods:

    void f() throws IOException Which of the following is/are correct overriding method? a) void f() throws IOException b) public void f() c) void f() throws FileNotFoundException d) void f() throws Exception


    • Dec 24th, 2012

    a) void f() throws ioexception Bcoz the overriding method must NOT throw checked exceptions that are new or broader than those declared by the overridden method. For example, a method that declares a...

  • Which of the following is true about packages?

    a) Classes in the same package can access each other. b) The inherited class should be in the same package as the parent class. c) Package name a.b implies, package b is inherits from package a. d) Package access is next to private access in being restrictive.


    • Feb 5th, 2013

    I think your first option is true. But any how these things depends on access specifiers. If you are not specifying any access specifier default package level access will be applied to the classes, wh...

  • Predict the output of the given code:

    {geshibot language="java"}public class Test { private static String msg = "HCL "; static{ Thread t = new Thread(new Runnable(){ public void run(){ msg = "Technologies "; } }); t.start(); } public static void main(String[] args){ System.out.print(msg); }}{/geshibot} a) Compiles and prints HCL b) Compiles and prints Technologies c) Compiles and prints HCL Technologies d) Output can be HCL or Technologies


    • Jan 29th, 2015



    • Dec 19th, 2014

    Answer is coming as HCL because there are two threads main and t and both are sharing the common resource ( static variable msg ) . Thread t is getting created and brought into runnable state ( by ca...

  • Which of the following options can be inserted at the commented line to compile the given code:

    {geshibot language="c"}public class Class1 { Class1(String s){ } Class1() { } } class Class2 extends Class1{ Class2(){ } Class2(String s) {super(s);} void m1() { // insert code here } }{/geshibot} a) Class1 c1 = new Class1("HCL"){ } b) Class1 c1 = new Class2(){ }; c) Class2 c3 = new Class1(String s){}; d) Class1 c1 = new Class1(100){ };

    Abhinav Rohatgi

    • Apr 1st, 2013

    Both a & b


    • Mar 29th, 2013

    A & b

  • What will be the result of compiling and executing the code listed below?

    {geshibot language="java"} public class Finder { public static void main(String[] args){ System.out.println(X.Y.Z); }} class X{ static class Y{ static String Z ="Apple"; } static W Y = new W(); } class W{ String Z = "Orange";}{/geshibot} a) Apple b) Orange c) Compile time Error d) Runtime Exception is thrown


    • Jun 28th, 2016

    B) Orange

    Abhinav Rohatgi

    • Apr 1st, 2013


  • Select appropriate answers for the incomplete declaration listed below?

    class A ______ B ______ C { } // line 4 a) The 1st blank should be extends and the 2nd blank should be implements. b) The 1st blank should be implements and the 2nd blank should be extends. c) B is a class and C is an interface d) B and C can be either class or interface depending upon the placement of extends or implements in the 1st or 2nd blank.

    Abhinav Rohatgi

    • Mar 30th, 2013

    A) is the correct answer because a class firstly extends another class & then implements interface.

  • What will be output if you will execute following c code?

    {geshibot language="c"} #i ain() { float p=1,q=2,r=-2,a; a=avg(p,(q=4,r=-12,q),r); printf("%f",a); return 0; } float avg(float x,float y,float z) { return (x+y+z)/3; }{/geshibot} a) 1.000000 b) 0.333333 c) -2.333333 d) 1

    Howard Lee Harkness

    • Apr 4th, 2013

    The real answer is that any programmer who would write this kind of code should be given the opportunity to work for the competition.

    The sequence expression (q=4,r=-12,q) evaluates to 4 (the last element), with the side-effect of assigning r the value -12. So, avg(1,4,-12) = -7/3 = -2.33...


    • Feb 15th, 2013

    Avg(1,-6,-2)/3 =-2.3333

  • What is the output of the following program:

    {geshibot language="c"}int main() { char a = 120, b = 140; int i; i = a + b; printf("%d", i); return 0; }{/geshibot} a) 260 b) 0 c) -1 d) 1

    Surajsingh Rajput

    • Feb 12th, 2014

    The answer is 4. because range of char is -128 to 127 so at 140 it get considered as 127,-128,-127,-126,....,-116.
    so 120+(-116)=4

    ish mahajan

    • Jan 16th, 2014