Near Hire 2017 Pretest

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Jesie
J
Jesie
Community Contributor
Quizzes Created: 1 | Total Attempts: 113
Questions: 15 | Attempts: 113

SettingsSettingsSettings
Near Hire 2017 Pretest - Quiz


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.

    Correct Answer
    E. The program will compile and run successfully.
    Explanation
    The program will compile and run successfully because there is no syntax error or logical inconsistency in the code. The fact that the static method main is trying to call the non-static method func does not cause a compilation error, as long as an instance of the class is created to call the non-static method. The non-static method func can access the static member variable ref without any issues. The argument args passed to the static method main can be passed on to the non-static method func without any compilation errors. There is no attempt to assign to the non-static member variable 'arguments' through the static member variable ref, so that does not cause a compilation error.

    Rate this question:

  • 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;

    Correct Answer(s)
    B. Int a, b, c; a = b = c = 100;
    C. Int a, b, c=100;
    D. Int a=100, b, c;
    Explanation
    The first option "int a, b, c; a = b = c = 100;" is a valid code snippet because it declares three integer variables (a, b, and c) and assigns the value 100 to all of them.

    The second option "int a, b, c=100;" is also valid because it declares three integer variables (a, b, and c) and initializes c with the value 100.

    The third option "int a=100, b, c;" is valid as well because it declares three integer variables (a, b, and c) and initializes a with the value 100.

    Therefore, the correct answer is the combination of these three options.

    Rate this question:

  • 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.

    Correct Answer(s)
    A. Replace the method body of m2() with a ; (semi-colon).
    C. Remove abstract from m2().
    Explanation
    The correct answer is to replace the method body of m2() with a ; (semi-colon) and to remove abstract from m2(). By replacing the method body of m2() with a semi-colon, it becomes an abstract method with no implementation. Removing the abstract keyword from m2() is necessary because abstract methods can only exist in abstract classes.

    Rate this question:

  • 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.

    Correct Answer(s)
    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.
    Explanation
    A class may contain both static and non-static variables and both static and non-static methods. This means that a class can have variables and methods that are shared among all instances of the class (static) as well as variables and methods that are unique to each instance of the class (non-static). Each object of a class has its own copy of each non-static member variable, which means that each instance of the class can have its own values for these variables.

    Rate this question:

  • 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{ }

    Correct Answer(s)
    A. Import java.lang.*;
    B. Package p.util;
    D. Abstract class MyClass{ }
    Explanation
    The correct answer is "import java.lang.*;", "package p.util;", and "abstract class MyClass{ }".

    The first option "import java.lang.*;" is necessary to import the java.lang package, which contains fundamental classes and interfaces that are automatically imported into every Java program.

    The second option "package p.util;" is used to declare that the class belongs to the "p.util" package. Packages are used to organize classes and avoid naming conflicts.

    The third option "abstract class MyClass{ }" defines an abstract class named MyClass. Abstract classes cannot be instantiated, but they can be extended by other classes.

    Together, these options provide the necessary import statement, package declaration, and class definition to successfully compile the code.

    Rate this question:

  • 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?

    Correct Answer(s)
    5
  • 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.*;

    Correct Answer(s)
    C. Import static x.y.SM.foo;
    E. Import static x.y.SM.*;
    Explanation
    The correct answer is "import static x.y.SM.foo;" and "import static x.y.SM.*;". Both of these import statements are necessary for the TestClass to compile and run successfully. The first import statement "import static x.y.SM.foo;" imports the specific static method "foo" from the class SM in the package x.y. The second import statement "import static x.y.SM.*;" imports all the static members (fields and methods) from the class SM in the package x.y.

    Rate this question:

  • 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

    Correct Answer(s)
    B. A field declaration
    C. A method declaration
    Explanation
    A Java class declaration can contain both a field declaration and a method declaration. A field declaration is used to define variables that belong to the class, while a method declaration is used to define the behavior or actions that the class can perform. Both of these elements are essential components of a Java class and can be included within the class declaration.

    Rate this question:

  • 9. 

    What is the result if the integer xVar is 9?

    Correct Answer(s)
    10 Hello World!
    Explanation
    When the integer variable xVar is equal to 9, the result is "10 Hello World!" This suggests that the value of xVar is being ignored or not used in the given statement. The statement "10 Hello World!" is a fixed string that does not change regardless of the value of xVar.

    Rate this question:

  • 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.

    Correct Answer
    D. The class will fail to compile.
    Explanation
    The class will fail to compile because the class OtherClass is used before it is defined. In Java, classes need to be defined before they can be used.

    Rate this question:

  • 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.

    Correct Answer
    C. The program will print "no arguments" when called with zero argument and "1 arguments" when called with one argument.
    Explanation
    The correct answer is the option that states that the program will print "no arguments" when called with zero arguments and "1 argument" when called with one argument. This answer is correct because it accurately describes the expected behavior of the program. When the program is called with zero arguments, it will print "no arguments". When the program is called with one argument, it will print "1 argument". This answer aligns with the given question and provides the expected output for different scenarios.

    Rate this question:

  • 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;

    Correct Answer
    C. Obj = null;
    Explanation
    Setting the reference variable "obj" to null at // 1 will make the object referred to by "obj" eligible for garbage collection. When an object no longer has any references pointing to it, it becomes eligible for garbage collection. By setting "obj" to null, we remove the reference to the object, indicating that it is no longer needed and can be safely collected by the garbage collector.

    Rate this question:

  • 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;

    Correct Answer(s)
    A. I = this.i1;
    B. I = this.i2;
    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;

    Correct Answer
    C. Return new DBConfiguration();
    Explanation
    To enable the code to compile, the correct code fragment that must be inserted at line 12 is "return new DBConfiguration();". This code creates a new instance of the DBConfiguration class and returns it. Since the return type of the method is DB Configuration, returning a new instance of the DBConfiguration class is necessary for the code to compile successfully.

    Rate this question:

  • 15. 

    What is the result?

    Correct Answer
    11 : 24 : 24

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Dec 06, 2017
    Quiz Created by
    Jesie
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.