Java Questions 21 - 30  «Prev  Next»

Java Questions 21

  1. What is the purpose of the keyword strictfp?

    strictfp forces floating points to adhere to the IEEE 754 standard.
    The keyword strictfp can only be used with classes, interfaces and non-abstract methods.

  2. What can strictfp modify?

    stictfp can modify a 1) class or 2) non-abstract method declarations. A variable (such as a primitive int) can never be declared strictfp.

  3. What is the purpose of Java var-args syntax?

    The purpose of Java var-args is to allow you to create methods that can take a variable number of arguments.

  4. What is the name for the elements that you specify between the parentheses when you are invoking a method in Java?

    These are known as arguments.
    The "method call" below contains two arguments:
     getSalary("name", age);

  5. What are the elements in the method's signature that indicate what the method must receive when the method is called?

    These are known as parameters. The method declaration below contains 2 parameters.
    Employee getSalary (String name, int age) {} 

  6. Where does the "var-arg" parameter appear in a method declaration?

    In a method declaration, the var-arg must appear last.
    static int sum (int ... numbers){
     int total = 0;
      for (int i = 0; i &t; numbers.length; i++)
       total += numbers [i];
      return total;

  7. What happens every time a new object is created?

    Everytime you make a new object, at least one constructor is invoked.

  8. When does the default "no-args" constructor get created?

    When you do not explicitly provide a constructor, the compiler will create a default "no-args" constructor.

  9. Do constructors have a reutrn type?

    No, constructors do not have a return type and only methods have a return type.

  10. What type of access modifiers can constructors have?

    Constructors can have the standard access modifiers,
    public, protected, default, private and they can take arguments (including var-args), just like methods.