Near Hire 2017 Pretest

15 Questions | Total Attempts: 89

SettingsSettingsSettings
Please wait...
Near Hire 2017 Pretest

Questions and Answers
  • 1. 
    What would be the result of attempting to compile and run the followingprogram?
    • A. 

      The program will fail to compile, since the static method main is trying to call the nonstatic method func.

    • B. 

      The program will fail to compile, since the non-static method func cannot access the static member variable ref.

    • C. 

      The program will fail to compile, since the argument args passed to the static method main cannot be passed on to the non-static method func.

    • D. 

      The program will fail to compile, since method func is trying to assign to the nonstatic member variable 'arguments' through the static member variable ref.

    • E. 

      The program will compile and run successfully.

  • 2. 
    Which of the following are valid code snippets appearing in a method? You hadto select 3 options.
    • A. 

      Int a = b = c = 100;

    • B. 

      Int a, b, c; a = b = c = 100;

    • C. 

      Int a, b, c=100;

    • D. 

      Int a=100, b, c;

    • E. 

      Int a= 100 = b = c;

  • 3. 
    Which of the following corrections can be applied to the above code (independently) sothat it compiles without any error? You had to select 2 options.
    • A. 

      Replace the method body of m2() with a ; (semi-colon).

    • B. 

      Replace the ; at the end of m1() with a method body.

    • C. 

      Remove abstract from m2().

    • D. 

      Remove abstract from the class declaration.

  • 4. 
    Which of these statements are true? You had to select 2 options
    • A. 

      A static method can call other non-static methods in the same class by using the 'this' keyword.

    • B. 

      A class may contain both static and non-static variables and both static and non-static methods.

    • C. 

      Each object of a class has its own copy of each non-static member variable.

    • D. 

      All methods in a class are implicitly passed a 'this' parameter when called.

  • 5. 
    Which of the given options can be successfully inserted at line 1? You had toselect 3 options.
    • A. 

      Import java.lang.*;

    • B. 

      Package p.util;

    • C. 

      Public class MyClass{ }

    • D. 

      Abstract class MyClass{ }

  • 6. 
    Which is the earliest line in the following code after which the object created on line // 1 can be garbage collected, assuming no compiler optimizations are done?
  • 7. 
    What should be inserted at //1 so that TestClass will compile and run? You had to select 2 options.
    • A. 

      Import static x.y.*

    • B. 

      Import static x.y.SM;

    • C. 

      Import static x.y.SM.foo;

    • D. 

      Import static x.y.SM.foo();

    • E. 

      Import static x.y.SM.*;

  • 8. 
    Which two items can legally be contained within a Java class declaration?
    • A. 

      An import statement

    • B. 

      A field declaration

    • C. 

      A method declaration

    • D. 

      A package declaration

  • 9. 
    What is the result if the integer xVar is 9?
  • 10. 
    What will be result of attempting to compile this class?
    • A. 

      The class will fail to compile, since the class OtherClass is used before it is defined.

    • B. 

      There is no problem with the code.

    • C. 

      The class will fail to compile, since the class OtherClass must be defined in a file called OtherClass.java

    • D. 

      The class will fail to compile.

    • E. 

      None of the above.

  • 11. 
    Which one do you like?
    • A. 

      The program will fail to compile.

    • B. 

      The program will throw a NullPointerException when run with zero arguments.

    • C. 

      The program will print "no arguments" when called with zero argument and "1 arguments" when called with one argument.

    • D. 

      The program will print "no arguments" and "2 arguments" when called with zero and one arguments.

    • E. 

      The program will print "no arguments" and "3 arguments" when called with zero and one arguments.

  • 12. 
    What can be inserted at // 1, which will make the object referred to by obj eligible for garbage collection?
    • A. 

      Obj.destroy();

    • B. 

      Runtime.getRuntime().gc();

    • C. 

      Obj = null;

    • D. 

      Obj.finalize();

    • E. 

      Obj.name = null; as well as obj = null;

  • 13. 
    Given the following code, which statements can be placed at the indicatedposition without causing compile and run time errors? You had to select 3 options.
    • A. 

      I = this.i1;

    • B. 

      I = this.i2;

    • C. 

      This = new Test( );

    • D. 

      This.i = 4;

    • E. 

      This.i1 = i2;

  • 14. 
    Which code fragment must be inserted at line 12 to enable the code to compile?
    • A. 

      DB Configuration f; return f;

    • B. 

      Return DBConfiguration;

    • C. 

      Return new DBConfiguration();

    • D. 

      Return 0;

  • 15. 
    What is the result?
Back to Top Back to top